[issue36817] Add = to f-strings for easier debugging.

Eric V. Smith report at bugs.python.org
Tue May 7 04:17:50 EDT 2019


Eric V. Smith <eric at trueblade.com> added the comment:

> In you example the format spec is applied to both the value and the literal representation of the expression. Is it an error? I do not think this is an expected behavior.

No, you're misreading it. I admit that my example wasn't great. Try this one:

>>> for n in nums:
...   print(f'*{n=:+<30}*')
... 
*n=0.3333333333333333++++++++++++*
*n=1.0+++++++++++++++++++++++++++*
*n=10.0++++++++++++++++++++++++++*
*n=3.141592653589793+++++++++++++*

> If you want to apply it to both the literal expression and its value you can use the nested f-string: f"*{f'{n=}':30}*".

Correct. There's a similar discussion in issue36774.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36817>
_______________________________________


More information about the Python-bugs-list mailing list