Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7198

Re: Dynamic Zero Padding.

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '>>>>': 0.09; 'from:addr:python': 0.09; 'integers': 0.09; 'padding': 0.09; '>>>': 0.12; 'wrote:': 0.14; 'eg.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'pad': 0.16; 'padded': 0.16; 'padding.': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr :python-list': 0.16; 'insert': 0.19; 'header:In-Reply-To:1': 0.21; 'variable': 0.21; 'received:84': 0.25; 'testing': 0.27; 'all,': 0.30; 'print': 0.31; "can't": 0.32; 'someone': 0.33; 'to:addr :python-list': 0.33; 'header:User-Agent:1': 0.35; 'reply- to:addr:python.org': 0.35; 'desirable': 0.37; 'tips': 0.37; 'but': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'sometimes': 0.39; 'to:addr:python.org': 0.39; 'format': 0.40; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'amount.': 0.84; 'fashion,': 0.84
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result Ag8GADmf7k1UXebj/2dsb2JhbABTl3uOKHfIRYYhBJVWino
Date Tue, 07 Jun 2011 23:00:00 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
MIME-Version 1.0
To python-list@python.org
Subject Re: Dynamic Zero Padding.
References <BANLkTik3hcA2vVfs3jCnbcRdh3_rKhU3ow@mail.gmail.com>
In-Reply-To <BANLkTik3hcA2vVfs3jCnbcRdh3_rKhU3ow@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
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.7.1307484064.11593.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 82.94.164.166
X-Trace 1307484065 news.xs4all.nl 49176 [::ffff:82.94.164.166]:48036
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7198

Show key headers only | View raw


On 07/06/2011 22:36, Friedrich Clausen wrote:
> 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.
>
 >>> "Testing %0*i" % (4, 1)
'Testing 0001'
 >>> "Testing %0*i" % (5, 1)
'Testing 00001'

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Dynamic Zero Padding. MRAB <python@mrabarnett.plus.com> - 2011-06-07 23:00 +0100

csiph-web