This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients gvanrossum
Date 2019-05-14.02:54:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1557802444.81.0.632526308066.issue36912@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2019-05-14 02:54:04gvanrossumsetrecipients: + gvanrossum
2019-05-14 02:54:04gvanrossumsetmessageid: <1557802444.81.0.632526308066.issue36912@roundup.psfhosted.org>
2019-05-14 02:54:04gvanrossumlinkissue36912 messages
2019-05-14 02:54:04gvanrossumcreate