[Python-Dev] Subtle difference between f-strings and str.format() (original) (raw)
Paul Moore p.f.moore at gmail.com
Wed Mar 28 15:21:15 EDT 2018
- Previous message (by thread): [Python-Dev] Subtle difference between f-strings and str.format()
- Next message (by thread): [Python-Dev] Subtle difference between f-strings and str.format()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 28 March 2018 at 20:12, Serhiy Storchaka <storchaka at gmail.com> wrote:
28.03.18 22:05, Paul Moore пише
I can't imagine (non-contrived) code where the fact that a is formatted before b is evaluated would matter, so I'm fine with option 3.
If formatting a and evaluating b both raise exceptions, the resulting exception depends on the order. $ ./python -bb
a = b'bytes' '{}{}'.format(a, b) Traceback (most recent call last): File "", line 1, in NameError: name 'b' is not defined f'{a}{b}' Traceback (most recent call last): File "", line 1, in BytesWarning: str() on a bytes instance
Thanks, I hadn't thought of that. But I still say that code that depends on which exception was raised is "contrived".
Anyway, Guido said #3, so no reason to debate it any further :-)
Paul
- Previous message (by thread): [Python-Dev] Subtle difference between f-strings and str.format()
- Next message (by thread): [Python-Dev] Subtle difference between f-strings and str.format()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]