Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7215
| References | <mailman.1.1307482621.11593.python-list@python.org> <ism61s$grp$1@speranza.aioe.org> <4DEEAECB.4070601@codicesoftware.com> <ismod9$4t2$1@dough.gmane.org> |
|---|---|
| Date | 2011-06-08 09:00 +0200 |
| Subject | Re: Dynamic Zero Padding. |
| From | Friedrich Clausen <fred@derf.nl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.22.1307516436.11593.python-list@python.org> (permalink) |
On Wed, Jun 8, 2011 at 4:56 AM, Terry Reedy <tjreedy@udel.edu> wrote:
> 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'
Thanks all for the many good suggestions - I am looking over them and
reading the referenced docs.
Cheers,
Fred.
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