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!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '>>>>': 0.09; 'integers': 0.09; 'padding': 0.09; 'pm,': 0.10; 'wrote:': 0.14; 'eg.': 0.16; 'pad': 0.16; 'padded': 0.16; 'padding.': 0.16; 'cc:addr:python- list': 0.17; 'tue,': 0.17; 'cheers,': 0.19; 'insert': 0.19; 'header:In-Reply-To:1': 0.21; 'variable': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'received:209.85.220': 0.25; 'testing': 0.27; 'message-id:@mail.gmail.com': 0.28; 'all,': 0.30; 'cc:addr:python.org': 0.30; 'url:library': 0.31; 'print': 0.31; "can't": 0.32; 'someone': 0.33; 'chris': 0.34; 'received:google.com': 0.37; 'received:209.85': 0.37; 'desirable': 0.37; 'tips': 0.37; 'url:docs': 0.37; 'url:python': 0.38; 'url:org': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'sometimes': 0.39; 'received:209': 0.39; 'format': 0.40; 'amount.': 0.84; 'fashion,': 0.84; 'sender:addr:chris': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=MKTQ7EA8spo0g62ec4CUFoXsTuJmiMXaTvuDRmKJaxg=; b=bwwMX5N5VafJvLlUEY8N1GzQb50Swy8xady/rnxnIZ+VzjtY4VY3/tjaWhs5UZsFoU JzYbrp/sBoyt8K4UNHp6gmOzyGOp7a3OWlf7+1W3dAPydgVIciGCRkY3VtL6ckRRKa8W nrB6xoLl+8ZE8sMQYrHXZgDqzEqahVC5tW2Do= DomainKey-Signature: a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=VJt/C7jSNrvubdJDJrZav4P2rVIbaXiQR74iV3ORdE7VG04xV+lmoIoo3mtRuqsZt4 39omNm+7KjOUeY7UUNhzV/E9UTCkYkhsz0CFzkUIj0o1kn+dxbLOAc3zVK5JjvIZ09hL lDHnR42VlVUBcuAjhJTCcDQ78mEgH7IkJY8a0= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Tue, 7 Jun 2011 14:44:58 -0700 X-Google-Sender-Auth: ZVeGFFhBDVxdDuZvjJeG_mza1lE Subject: Re: Dynamic Zero Padding. From: Chris Rebert To: Friedrich Clausen Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307483101 news.xs4all.nl 49179 [::ffff:82.94.164.166]:36505 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7191 On Tue, Jun 7, 2011 at 2:36 PM, 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. http://docs.python.org/library/stdtypes.html#str.zfill Cheers, Chris