Message342421
I sometimes like to use format specs like "%-10s" % foo, which left-aligns the string foo in a field of 10 spaces:
>>> '%10s' % foo
' abc'
>>> foo = 'abc'
>>> '%-10s' % foo
'abc '
This is documented in "Format Specification Mini-Language":
https://docs.python.org/3/library/string.html#format-specification-mini-language
However it does not work with format() and f-strings:
>>> format(foo, '10s')
'abc '
>>> format(foo, '-10s')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Sign not allowed in string format specifier
>>> f'{foo:10}'
'abc '
>>> f'{foo:-10}'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Sign not allowed in string format specifier
In each case, without a sign it works, and right-aligns.
What am I missing? |
|
Date |
User |
Action |
Args |
2019-05-14 02:54:04 | gvanrossum | set | recipients:
+ gvanrossum |
2019-05-14 02:54:04 | gvanrossum | set | messageid: <1557802444.81.0.632526308066.issue36912@roundup.psfhosted.org> |
2019-05-14 02:54:04 | gvanrossum | link | issue36912 messages |
2019-05-14 02:54:04 | gvanrossum | create | |
|