Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7209
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Dynamic Zero Padding. |
| Date | 2011-06-07 22:56 -0400 |
| References | <mailman.1.1307482621.11593.python-list@python.org> <ism61s$grp$1@speranza.aioe.org> <4DEEAECB.4070601@codicesoftware.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13.1307501817.11593.python-list@python.org> (permalink) |
On 6/7/2011 7:05 PM, John Posner wrote:
> You might want to try "new style" string formatting [1], which I think
> is better than the "old style" in this particular case:
>
> >>> "Testing {0:0{1}d}".format(42, 4)
> 'Testing 0042'
> >>> "Testing {0:0{1}d}".format(42, 9)
> 'Testing 000000042'
One cannot use a nested field in the 'name' part of the field (before
the ':' (I tried), but are pretty free to nest in the actual
specification part after the ':'.
>>> '{0:{1}}'.format(7,'b')
'111'
>>> '{0:{1}}'.format(7,'d')
'7'
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Dynamic Zero Padding. Friedrich Clausen <fred@derf.nl> - 2011-06-07 23:36 +0200
Re: Dynamic Zero Padding. Mel <mwilson@the-wire.com> - 2011-06-07 17:43 -0400
Re: Dynamic Zero Padding. Chris Angelico <rosuav@gmail.com> - 2011-06-08 09:26 +1000
Re: Dynamic Zero Padding. Terry Reedy <tjreedy@udel.edu> - 2011-06-07 22:56 -0400
Re: Dynamic Zero Padding. Friedrich Clausen <fred@derf.nl> - 2011-06-08 09:00 +0200
Re: Dynamic Zero Padding. harrismh777 <harrismh777@charter.net> - 2011-06-07 16:55 -0500
csiph-web