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


Groups > comp.lang.python > #7193

Re: Dynamic Zero Padding.

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'width': 0.07; '>>>>': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'integers': 0.09; 'message- id:@stoneleaf.us': 0.09; 'padding': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'wrote:': 0.14; "'*'": 0.16; '1))': 0.16; 'eg.': 0.16; 'pad': 0.16; 'padded': 0.16; 'padding.': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'cc:addr:python-list': 0.17; '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; 'testing': 0.27; 'all,': 0.30; 'cc:addr:python.org': 0.30; 'print': 0.31; "can't": 0.32; 'someone': 0.33; 'header:User-Agent:1': 0.35; 'desirable': 0.37; 'tips': 0.37; 'but': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'sometimes': 0.39; 'format': 0.40; 'received:websitewelcome.com': 0.67; 'holder': 0.67; 'received:69.93': 0.67; 'acts': 0.77; '001': 0.84; 'amount.': 0.84; 'fashion,': 0.84
Date Tue, 07 Jun 2011 15:04:35 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To Friedrich Clausen <fred@derf.nl>
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-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:2891
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
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 <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.5.1307483556.11593.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 82.94.164.166
X-Trace 1307483556 news.xs4all.nl 49042 [::ffff:82.94.164.166]:42074
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7193

Show key headers only | View raw


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.

--> width = 3
--> print("Testing %0*i" % (width, 1))
Testing 001
--> width = 7
--> print("Testing %0*i" % (width, 1))
Testing 0000001

The '*' acts as a place holder for the width argument.

~Ethan~

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


Thread

Re: Dynamic Zero Padding. Ethan Furman <ethan@stoneleaf.us> - 2011-06-07 15:04 -0700
  Re: Dynamic Zero Padding. harrismh777 <harrismh777@charter.net> - 2011-06-07 17:01 -0500
    Re: Dynamic Zero Padding. Larry Hudson <orgnut@yahoo.com> - 2011-06-07 18:46 -0700

csiph-web