[Python-Dev] PEP-498: Literal String Formatting
Victor Stinner
victor.stinner at gmail.com
Mon Aug 17 06:34:49 CEST 2015
2015-08-16 7:21 GMT-07:00 Paul Moore <p.f.moore at gmail.com>:
> 2. By far and away the most common use for me would be things like
> print(f"Iteration {n}: Took {end-start) seconds"). At the moment I use
> str,format() for this, and it's annoyingly verbose. This would be a
> big win, and I'm +1 on the PEP for this specific reason.
You can use a temporary variable, it's not much longer:
print("Iteration {n}: Took {dt) seconds".format(n=n, dt=end-start))
becomes
dt = end - start
print(f"Iteration {n}: Took {dt) seconds")
> 3. All of the complex examples look scary, but in practice I wouldn't
> write stuff like that - why would anyone do so unless they were being
> deliberately obscure?
I'm quite sure that users will write complex code in f-strings.
I vote -1 on the current PEP because of the support of Python code in
f-string, but +1 on a PEP without Python code.
Victor
More information about the Python-Dev
mailing list