I think {} formatting has some minor readability benefits. The symmetry of
the braces makes it easier (imo) to see at a glance what is going to be
interpolated. With % formatting the alphabetical characters can be obscured
by other text in the string, especially if there's not a space after it.
I've often wished string templates in Django form error messages could be
overwritten with a {} formatted string. On the other hand making a change
would be a lot of churn and I'm not sure the benefit would be worth it.Ian On Wed, 31 Oct 2018 at 22:54, Tim Graham <[email protected]> wrote: > Another discussion is > https://groups.google.com/d/topic/django-developers/J9CfWIgrgbY/discussion > - % vs {} string formatting for public APIs > > I haven't seen any practical benefits to prefer format() over %s. I find > the latter less verbose. > > I'm not certain what this argument is (things like > http://lucumr.pocoo.org/2016/12/29/careful-with-str-format/ I imagine) > but here's a previous concern that Florian raised regarding f-strings: > "Knowing what certain members of the core team think about those > f-strings, I think there will be first a big discussion if we will allow > them at all in Django's codebase. Then there are further things to consider > like gettext support etc…" > https://groups.google.com/d/msg/django-developers/4rbVKJYm8DI/y9VNRBw0AgAJ > > On Wednesday, October 31, 2018 at 6:28:08 PM UTC-4, Tom Forbes wrote: >> >> In my experience f strings are vastly more expressive than .format, but >> not much better than % based formatting. >> >> If we can make this change after we drop 3.5 I think it will be a lot >> easier. >> >> On Wed, 31 Oct 2018, 21:09 Adrian Turjak <[email protected] wrote: >> >>> There was a push to deprecated % formatting but too many people >>> complained and that never happened. >>> >>> While .format and g-strings are superior, % is here to stay for the >>> foreseeable future. Too many people still use it (including myself >>> sometimes). >>> >>> On 1 Nov. 2018 08:14, Carlton Gibson <[email protected]> wrote: >>> >>> We had a bit of a discussion of this on >>> >>> >>> Python 2 docs have got this re format(): >>> >>> > This method of string formatting is the new standard in Python 3, and >>> should be preferred to the % formatting described in String Formatting >>> Operations in new code. >>> >>> https://docs.python.org/2/library/stdtypes.html#str.format >>> >>> But it's not there for Python 3 ( >>> https://docs.python.org/3/library/stdtypes.html#str.format) so I'm not >>> clear what we're meant to think. >>> (I had thought %-formatting deprecated...) >>> >>> Anyone know? >>> >>> Regardless, waiting a bit and moving straight to f-strings (as Simon >>> suggests) seems sensible. (If we're convinced we do want to change.) >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django developers (Contributions to Django itself)" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at https://groups.google.com/group/django-developers. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-developers/e7cf5b0d-cff4-4c6d-a9ec-1af4a82d5a56%40googlegroups.com >>> <https://groups.google.com/d/msgid/django-developers/e7cf5b0d-cff4-4c6d-a9ec-1af4a82d5a56%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django developers (Contributions to Django itself)" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at https://groups.google.com/group/django-developers. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-developers/6b09193b-a53f-4eb4-9f36-2c7aa11f47cb%40email.android.com >>> <https://groups.google.com/d/msgid/django-developers/6b09193b-a53f-4eb4-9f36-2c7aa11f47cb%40email.android.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-developers. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/65527cfe-d970-47b4-828c-7f55312d2120%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/65527cfe-d970-47b4-828c-7f55312d2120%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAFv-zfKEH1QwhNcBu2L7GD93%3Den%3DrX%2BH23pYiawG-3kE354RoQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
