Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!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.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'integers': 0.09; 'padding': 0.09; '>>>': 0.12; 'eg.': 0.16; 'from:addr:fred': 0.16; 'pad': 0.16; 'padded': 0.16; 'padding.': 0.16; 'cheers,': 0.19; 'thanks,': 0.19; 'insert': 0.19; 'variable': 0.21; 'testing': 0.27; 'message-id:@mail.gmail.com': 0.28; 'all,': 0.30; 'print': 0.31; "can't": 0.32; 'someone': 0.33; 'to:addr:python-list': 0.33; 'received:209.85.212': 0.34; 'received:google.com': 0.37; 'received:209.85': 0.37; 'desirable': 0.37; 'tips': 0.37; 'but': 0.38; 'some': 0.38; 'sometimes': 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'format': 0.40; 'amount.': 0.84; 'fashion,': 0.84; 'received:209.85.212.178': 0.91; 'received:mail- px0-f178.google.com': 0.91 MIME-Version: 1.0 Date: Tue, 7 Jun 2011 23:36:58 +0200 Subject: Dynamic Zero Padding. From: Friedrich Clausen To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 21 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307482622 news.xs4all.nl 49044 [::ffff:82.94.164.166]:38171 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7188 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. Cheers, Fred. Thanks, Fred.