Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7192
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; '>>>>': 0.09; 'integers': 0.09; 'padding': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; '>>>': 0.12; 'eg.': 0.16; 'pad': 0.16; 'padded': 0.16; 'padding.': 0.16; 'insert': 0.19; 'header :In-Reply-To:1': 0.21; 'variable': 0.21; 'testing': 0.27; 'all,': 0.30; 'skip:( 20': 0.30; 'print': 0.31; "can't": 0.32; 'header:X -Complaints-To:1': 0.32; 'someone': 0.33; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.35; 'something': 0.37; 'desirable': 0.37; 'tips': 0.37; 'received:org': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'sometimes': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'format': 0.40; 'received:173': 0.60; '0140': 0.84; 'amount.': 0.84; 'fashion,': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Emile van Sebille <emile@fenx.com> |
| Subject | Re: Dynamic Zero Padding. |
| Date | Tue, 07 Jun 2011 14:50:56 -0700 |
| References | <BANLkTik3hcA2vVfs3jCnbcRdh3_rKhU3ow@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | 173-11-108-137-sfba.hfc.comcastbusiness.net |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 |
| In-Reply-To | <BANLkTik3hcA2vVfs3jCnbcRdh3_rKhU3ow@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4.1307483354.11593.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1307483355 news.xs4all.nl 49177 [::ffff:82.94.164.166]:39892 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:7192 |
Show key headers only | View raw
On 6/7/2011 2:36 PM Friedrich Clausen said...
> Hello All,
>
> I want to print some integers in a zero padded fashion, eg. :
>
>>>> print("Testing %04i" % 1)
> Testing 0001
>
> but the padding needs to be dynamic eg. sometimes %05i, %02i or some
> other padding amount. But I can't insert a variable into the format
> specification to achieve the desirable padding.
>
> I would be much obliged if someone can give me some tips on how to
> achieve a variably pad a number.
Something like this works:
>>> for ii in ((3,12),(4,140),(5,123)):
... print ("Testing %%%02ii" % ii[0]) % ii[1]
...
Testing 012
Testing 0140
Testing 00123
Emile
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Dynamic Zero Padding. Emile van Sebille <emile@fenx.com> - 2011-06-07 14:50 -0700
csiph-web