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

John Matthews jmatthews at mcb-inc.com
Thu May 6 08:51:11 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

Below is the code. I am not really a programmer, so it probably looks clunky
to you guys!

import os, glob, Image

print "\n  Where are the .bmp graphics?"
path = raw_input("  example:  C:\\foldername\\ >")

bmpfiles = glob.glob('*.bmp')
print '\nThere are',len(bmpfiles),'bmp files: \n'
while len(bmpfiles)>0:
    print imagesize, os.path.getsize(bmpfiles[-1]), bmpfiles[-1]

raw_input('\nPress Enter to end the program')

John Matthews
McDonald, Cassell & Bassett, Inc.
600 West Spring Street
Columbus, Ohio 43215
(614) 628-0630
(614) 628-0633 Fax
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040506/e1e23d30/attachment.html

More information about the Tutor mailing list