[Tutor] Re: How can I format rows of irregular sized strings to
print in columns?
Lee Harr
missive at hotmail.com
Thu May 6 18:31:31 EDT 2004
>I wrote a little program to look for graphics files and tell me the image
>size and the file size of each file. The data prints out like this:
>
>(292, 240) 35638 defender.bmp
>(1024, 768) 2359350 evolution3.bmp
>(78, 76) 17990 GRID1A.bmp
>
>How can I make it so that it looks more like this:
>
>( 292, 240) 35,638 defender.bmp
>(1024, 768) 2,359,350 evolution3.bmp
>( 78, 76) 17,990 GRID1A.bmp
>
Please post only in plain text.
You will want to look at the string formatting operator:
http://docs.python.org/lib/typesseq-strings.html
One handy example:
>>>a='(292, 240)';b=35638; c='defender.bmp'
>>>print '%10s %10s %20s' % (a, b, c)
(292, 240) 35638 defender.bmp
_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail
More information about the Tutor
mailing list