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


Groups > comp.lang.python > #7188

Dynamic Zero Padding.

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 <fred@derf.nl>
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 <fred@derf.nl>
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 <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.1.1307482621.11593.python-list@python.org> (permalink)
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

Show key headers only | View raw


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.

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


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