realpython / realpython/python-guide

Section idea: Elegant string formatting

Aperta
#859 1 commento 1 reazione 1 assegnatario Vedi su GitHub

@mpoulin ci sta già lavorando.

Dal 31/8/2018.

Lingua principale
Batchfile
Stelle
29.8k
Fork
5.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

One thing that I would love to see is an opinionated guide to elegant string formatting in python. I feel like there are many ways to do it, especially with f-strings now, and when it comes to indentation, interpolation, longer method names, etc, and I can never decide in the moment on what the most elegant approach is. This is especially hairy when trying to conform to a 79 character line length.

This seems obviously up the python guide's alley. ;) Just wanted to drop the seed in case it had ever crossed y'alls mind.

Some examples I can think of:

  1. What should a long string parameter in a method call look like? (This often comes up in exceptions being raised for example.)

  2. What should a long string parameter with interpolation in an error message look like?

  3. What should a string look like in a case with deep-ish indentation? (other than: break out to a method). Same question with interpolation.

  4. f-strings or .format() or %? When/why?

  5. What should multi-line f-strings look like? Should they be avoided?

  6. When to triple quote? Docs only?

etc

I feel like there's an opportunity for really good guidance here that is outside of pep8; something everybody would run into that you all would have well-formed opinions on. :) And I haven't seen much written about it.

Thoughts?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.