Have a variable column length in printf
Emile van Sebille
emile at fenx.com
Sun May 31 09:03:21 CEST 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
More information about the Python-list