Shouldn't %06s zero-pad a string?

Byron Morgan lazypointer at yahoo.com
Fri Feb 14 01:57:17 EST 2003


Doesn't seem to be a limitation, since you can easily get the desired zeroes
with zfill().

>>> '%s' % 'a'.zfill(6)
'00000a'


"Hans Nowak" <wurmy at earthlink.net> wrote in message
news:3E4C6640.2030601 at earthlink.net...
> Beat Bolli wrote:
>
> > Jeff Epler wrote:
> >
> >> so "the behavior is undefined" when the s conversion is used.
> >> The treatment of 0 as " " (space) seems fairly useful, though.
> >>
> > That's all fine, but the *Python* manual mentions no such limitation.
> > Wouldn't be simpler to handle all cases consistently?
>
> Padding a string with zeroes doesn't make a lot of sense.  Padding it with
> spaces seems more useful.  Practicality beats purity, and all that.
>
> > Still-wondering-whether-to-file-a-bug-ly yours
>
> I suppose you could file a documentation bug... a request to mention this
> behavior in the documentation.
>
> Cheers,
>
> --
> Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
> # decode for email address ;-)
> The Pythonic Quarter:: http://www.awaretek.com/nowak/
> Kaa:: http://www.awaretek.com/nowak/kaa.html
> Soon: http://zephyrfalcon.org/
>






More information about the Python-list mailing list