bug in ''.format()

Ken Kundert theNurd at nurdletech.com
Thu Nov 2 17:30:57 EDT 2017


I just encountered this:

>>> '{:0s}'.format('hello')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: '=' alignment not allowed in string format specifier

The exception goes away if I do not specify a width of the string:

>>> '{:s}'.format('hello')
'hello'

My reading of the documentation says I should be able to specify a width
when interpolating a string.

I have tried this in 2.7.13, 3.6.1 and 3.6.2 and it fails in all of them.

Is this a bug or am I confused?
-Ken



More information about the Python-list mailing list