Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7198 > unrolled thread
| Started by | MRAB <python@mrabarnett.plus.com> |
|---|---|
| First post | 2011-06-07 23:00 +0100 |
| Last post | 2011-06-07 23:00 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Dynamic Zero Padding. MRAB <python@mrabarnett.plus.com> - 2011-06-07 23:00 +0100
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2011-06-07 23:00 +0100 |
| Subject | Re: Dynamic Zero Padding. |
| Message-ID | <mailman.7.1307484064.11593.python-list@python.org> |
On 07/06/2011 22:36, 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.
>
>>> "Testing %0*i" % (4, 1)
'Testing 0001'
>>> "Testing %0*i" % (5, 1)
'Testing 00001'
Back to top | Article view | comp.lang.python
csiph-web