[Tutor] How can I format rows of irregular sized strings to print in colu mns?

David Rock david at graniteweb.com
Fri May 7 00:31:11 EDT 2004


* John Matthews <jmatthews at mcb-inc.com> [2004-05-06 08:51]:
> 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

You should probably look at the printf style formatting:
http://www.python.org/doc/current/lib/typesseq-strings.html#l2h-206

In general, your output string will probably look something like this:
print "(%5d,%5d) %12d %s" % (x,y,size,filename)

This is _very_ generic, and probably breaks often, but it should give
you an idea of what to look for.

-- 
David Rock
david at graniteweb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20040506/edbf89c5/attachment.bin


More information about the Tutor mailing list