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


Groups > comp.lang.python > #7196

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 <ramit.prasad@jpmchase.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'completeness': 0.05; 'python': 0.08; 'integers': 0.09; 'padding': 0.09; 'skip:{ 20': 0.09; 'to:name:python-list@python.org': 0.09; '>>>': 0.12; 'message-----': 0.12; "'test": 0.16; '712': 0.16; 'affiliates,': 0.16; 'currencies': 0.16; 'eg.': 0.16; 'opened,': 0.16; 'pad': 0.16; 'padded': 0.16; 'padding.': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:169.70': 0.16; 'received:169.70.184': 0.16; 'received:172.18.0': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'solicitation': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'cheers,': 0.19; 'thanks,': 0.19; 'insert': 0.19; 'to:2**1': 0.20; 'header:In- Reply-To:1': 0.21; 'variable': 0.21; 'applicable,': 0.23; 'herein': 0.23; 'received:169': 0.25; 'received:169.254': 0.25; 'url:mailman': 0.26; 'testing': 0.27; 'reflect': 0.28; 'all,': 0.30; 'subject:': 0.30; 'url:listinfo': 0.30; 'chase': 0.30; 'received:155': 0.30; 'received:159': 0.30; 'received:169.254.1': 0.30; 'print': 0.31; 'header:Received:8': 0.32; "can't": 0.32; '(including': 0.32; 'someone': 0.33; 'to:addr:python-list': 0.33; 'sent:': 0.34; 'thank': 0.35; 'received:172.18': 0.35; 'skip:{ 10': 0.35; 'phone:': 0.36; 'format.': 0.36; 'from:': 0.36; 'accepted': 0.36; 'charset:us-ascii': 0.36; 'change': 0.37; 'accuracy': 0.37; 'arising': 0.37; 'desirable': 0.37; 'tips': 0.37; 'skip:- 10': 0.37; 'url:python': 0.38; 'url:org': 0.38; 'but': 0.38; 'data': 0.38; 'purposes': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'comments': 0.39; 'sometimes': 0.39; 'legally': 0.39; 'to:addr:python.org': 0.39; 'under': 0.40; 'format': 0.40; 'you.': 0.62; 'subject': 0.62; 'market': 0.63; 'virus': 0.63; 'free': 0.63; 'applicable': 0.65; 'co.,': 0.65; 'contact': 0.66; 'relating': 0.67; 'legal': 0.70; 'offer': 0.71; 'sale': 0.76; 'bank': 0.76; 'june': 0.77; 'investment': 0.78; 'purchase': 0.83; 'affiliates.': 0.84; 'amount.': 0.84; 'fashion,': 0.84; 'prices,': 0.84; 'defect': 0.91; 'instrument': 0.95; 'notice.': 0.96
X-DKIM Sendmail DKIM Filter v2.8.4 sz4.jpmchase.com p57Lson3005007
DKIM-Signature v=1; a=rsa-sha256; c=simple/simple; d=jpmchase.com; s=smtpout; t=1307483690; bh=buhOkQjre0ooLGbhyKcvukHS0zz4eNh6qUTMtN3dk3o=; h=From:To:Date:Subject:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=MPmO7ahLWJqVj336BZVM00WopbnBV60UHGHigj7grreGrBZzf7tzrt2VjqWAR7a5H 8wcujfyK4PajT1MdAhTT6ZVbGB8gFa4WmaKFata1hMim1Z0HHZnVAa12KBjz2VveuI JqyoCwFqCxGSiwwUgf2O+sXDp6YQd3pMng7t2Q7I=
From "Prasad, Ramit" <ramit.prasad@jpmchase.com>
To Friedrich Clausen <fred@derf.nl>, "python-list@python.org" <python-list@python.org>
Date Tue, 7 Jun 2011 17:54:41 -0400
Subject RE: Dynamic Zero Padding.
Thread-Topic Dynamic Zero Padding.
Thread-Index AcwlW6MzVM5YxL4LRvOcGZPjhPr1kgAAapfQ
References <BANLkTik3hcA2vVfs3jCnbcRdh3_rKhU3ow@mail.gmail.com>
In-Reply-To <BANLkTik3hcA2vVfs3jCnbcRdh3_rKhU3ow@mail.gmail.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
acceptlanguage en-US
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="us-ascii"
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.6.1307483788.11593.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 82.94.164.166
X-Trace 1307483788 news.xs4all.nl 49175 [::ffff:82.94.164.166]:59090
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7196

Show key headers only | View raw


Python 2.6.x
>>> 'test {0:.2f}'.format(1)
'test 1.00'
>>> 'test {0:{1}f}'.format(1,2)
'test 1.000000'
>>> 'test {0:{1}f}'.format(1,.2)
'test 1.00'
>>> 'test {0:.{1}f}'.format(1,2)
'test 1.00'


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


-----Original Message-----
From: python-list-bounces+ramit.prasad=jpmchase.com@python.org [mailto:python-list-bounces+ramit.prasad=jpmchase.com@python.org] On Behalf Of Friedrich Clausen
Sent: Tuesday, June 07, 2011 4:37 PM
To: python-list@python.org
Subject: Dynamic Zero Padding.

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.
-- 
http://mail.python.org/mailman/listinfo/python-list
This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.

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


Thread

RE: Dynamic Zero Padding. "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-06-07 17:54 -0400

csiph-web