On Wed, Jun 8, 2011 at 4:56 AM, Terry Reedy wrote:
> On 6/7/2011 7:05 PM, John Posner wrote:
>
>> You might want to try "new style" string formatting [1], which I think
>> is better than the "old style" in this particular case:
>>
>> >>> "Testing {0:0{1}d}".format(42, 4)
>> 'Testing 0042'
>
On 6/7/2011 7:05 PM, John Posner wrote:
You might want to try "new style" string formatting [1], which I think
is better than the "old style" in this particular case:
>>> "Testing {0:0{1}d}".format(42, 4)
'Testing 0042'
>>> "Testing {0:0{1}d}".format(42, 9)
'Testing 00042'
On 06/07/2011 03:01 PM, harrismh777 wrote:
Ethan Furman wrote:
--> print("Testing %0*i" % (width, 1))
The '*' acts as a place holder for the width argument.
very nice...
It works for precision as well as width.
wid = 10
prec = 3
num = 123.456789
print "%0*.*f" % (wid, prec, num)
gives
Friedrich:
>> I would be much obliged if someone can give me some tips on how to
>> achieve a variably pad a number.
> :)
>
> ('%%0%dd' % (pads,)) % (n,)
>
> Probably be good to wrap it in a function. It looks kind of obscure as it
> is.
You might want to try "new style" string formatting [1]
On Wed, Jun 8, 2011 at 7:43 AM, Mel wrote:
> :)
>
> ('%%0%dd' % (pads,)) % (n,)
>
> Probably be good to wrap it in a function. It looks kind of obscure as it
> is.
Would get rather pretty (read: ugly and impossible to read) if you
wanted to put a literal percent sign in front of the number.
:)
Ethan Furman wrote:
--> print("Testing %0*i" % (width, 1))
The '*' acts as a place holder for the width argument.
very nice...
--
http://mail.python.org/mailman/listinfo/python-list
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 form
Friedrich Clausen wrote:
I would be much obliged if someone can give me some tips on how to
achieve a variably pad a number.
b='04'
a="testing %"+b+"i"
print(a % 1)
testing 0001
kind regards,
m harris
--
http://mail.python.org/mailman/listinfo/python-list
Python 2.6.x
>>> 'test {0:.2f}'.format(1)
'test 1.00'
>>> 'test {0:{1}f}'.format(1,2)
'test 1.00'
>>> '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,
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 a
On 6/7/2011 2:36 PM Friedrich Clausen said...
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 form
Friedrich Clausen wrote:
> 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 t
On Tue, Jun 7, 2011 at 2:36 PM, 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 inser
13 matches
Mail list logo