[Python-Dev] Incorrect behavior in str.format() method when padding with '\x00'

John Tyree jtyree at enthought.com
Wed Apr 2 22:08:35 CEST 2014


Hi all,

Is there any particularly reason for the following behavior on both 2.7.6
and 3.4.0 ?

>>> "{:\x00<5}".format(2)
> '2    '
> >>>
> "{:\x20<5}".format(2)
>
> '2    '
> >>>
> "{:\x01<5}".format(2)
>
> '2\x01\x01\x01\x01'
> >>> "{:\x00<5}".format(2) ==
> "{:\x20<5}".format(2)
>
> True
>

The docs say "If a valid *align* value is specified, it can be preceded by
a *fill* character that can be any character and defaults to a space if
omitted," so I'm inclined to call this a good old fashioned bug.

-- 
John Tyree
Scientific Software Developer
Enthought, Inc.
www.enthought.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140402/533ac582/attachment.html>


More information about the Python-Dev mailing list