Message341691
> 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. |
|
Date |
User |
Action |
Args |
2019-05-07 07:32:42 | eric.smith | set | recipients:
+ eric.smith, barry, larry, serhiy.storchaka, levkivskyi |
2019-05-07 07:32:42 | eric.smith | set | messageid: <1557214362.77.0.89238608908.issue36817@roundup.psfhosted.org> |
2019-05-07 07:32:42 | eric.smith | link | issue36817 messages |
2019-05-07 07:32:42 | eric.smith | create | |
|