batch tiff to jpeg conversion script

rtilley at rtilley at
Wed Jan 11 13:59:06 EST 2006

Hope it's not inappropriate to post this here.

Could someone critique my code? I have no Python programmers in my
office to show this to. The script works OK, but should I do it
differently? I especially don't like how I check to see if jpegs exist.

The style may not be acceptable to some, but I'm concerned with
substance, not style. Is there a 'more appropriate' way to do this?

Thanks to all who take the time to give advice!

import os
import os.path
#From PIL
import Image

def tiff_to_jpeg(path):

    for root, dirs, files in os.walk(path):
        for f in files:
            if os.path.splitext(os.path.join(root,f))[1].lower() ==

                # If a jpeg is already present. Don't do anything.
os.path.isfile(os.path.splitext(os.path.join(root,f))[0] + ".jpg"):
                    print "A jpeg file already exists for %s" %f

                # If a jpeg is *NOT* present, create one from the tiff.
                    outfile = os.path.splitext(os.path.join(root,f))[0]
+ ".jpg"
                        im =,f))
                        print "Generating jpeg for %s" %f
              , "JPEG", quality=100)
                    except Exception, e:
                        print e

# Run Program
path = '.'

More information about the Python-list mailing list