Eric V. Smith <e...@trueblade.com> added the comment:

> Except that I think that !f is not needed. You can use repr by default only 
> when no format spec is specified, and add explicit !r if you want to use repr 
> with the format spec. If you want to format the value without repr and the 
> format spec -- specify the empty format spec: f"{foo=:}".

I had this working in issue36774, but it seems like a little too much magic. It 
also prevents you from formatting the result of the repr, which works in 
f-strings without the =.

Say you wanted a fixed width output. You need to apply a format to the value of 
the repr:

>>> nums = [1/3, 1.0, 10.0, math.pi]
>>> for n in nums:
...   print(f'*{n=}*')
... 
*n=0.3333333333333333*
*n=1.0*
*n=10.0*
*n=3.141592653589793*

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

If the presence of a format spec meant automatically apply the format to the 
value being printed, this wouldn't be possible.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36817>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to