Newbie Formatting Question

AdSR artur_spruce at yahoo.com
Tue Mar 23 04:44:36 EST 2004


Heather Coppersmith <me at privacy.net> wrote:
>     >>> for x in range( 10 ):
>          f = '%20.' + str( x ) + 'f' # or f = '%%20.%df' % x
>          print f % 1.2

Try this:

>>> for x in range(10):
	print "%20.*f" % (x, 1.2)

	
                   1
                 1.2
                1.20
               1.200
              1.2000
             1.20000
            1.200000
           1.2000000
          1.20000000
         1.200000000

You can use '*' for both width and precision.

Cheers,

AdSR



More information about the Python-list mailing list