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

Jp Calderone exarkun at intarweb.us
Fri Feb 14 00:11:30 CET 2003


On Thu, Feb 13, 2003 at 11:09:02PM +0100, Beat Bolli wrote:
> Jeff Epler wrote:
> >Python generally takes inspiration for the handling of %-formats from
> >the C standard.
> >
> >[Tests snipped]
> >
> >Here's what my printf manual page says about '0':
> >
> >       0      The value should be zero padded.  For d, i,  o,  u,
> >              x,  X,  a, A, e, E, f, F, g, and G conversions, the
> >              converted value is padded on the  left  with  zeros
> >              rather  than  blanks.   If  the  0 and - flags both
> >              appear, the 0 flag is ignored.  If a  precision  is
> >              given with a numeric conversion (d, i, o, u, x, and
> >              X), the 0 flag is ignored.  For other  conversions,
> >              the behavior is undefined.
> >
> >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?

  Simpler for whom?  (Answer this one in your head, please)

  If all you want is a string padded with zeros, use str.zfill().

  Jp

-- 
"There is no reason for any individual to have a computer in their
home."
                -- Ken Olson, President of DEC, World Future Society
                   Convention, 1977
-- 
 up 5 days, 4:28, 4 users, load average: 0.03, 0.01, 0.00
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030213/05c9932d/attachment.pgp>


More information about the Python-list mailing list