Have a variable column length in printf
Emile van Sebille
emile at fenx.com
Sun May 31 03:03:21 EDT 2009
On 5/30/2009 10:58 PM Cameron Pulsford said...
> Hello all, I'm trying to pretty print a list, so I am doing something like
>
> print '%3d' % integer
>
> only I would like that 3 to be a variable, instead of hardcoded. Is this
> possible, or are there any other ways to accomplish this? Thanks!
>
>>> integer = 12
>>> for lenvar in (4,5,6,7):
... print ("%%%sd" % lenvar) % integer
...
12
12
12
12
>>>
Emile
More information about the Python-list
mailing list