On 08/04/2012 09:11 PM, richard kappler wrote: > Starting to work through "Programming Computer Vision with Python" in my > -summer of learning python- quest.
Congratulations; that's a worthy goal. > As I read through the intro to the PIL > library, I came across the below code. When I read it, I said to my self > "I don't see how that calls a set of files, there's no specificity. How > does that know where to call from?" Then I convinced myself that, because > I'm a beginner, I must be missing something, and ran it through the > interpreter. Of course, I got an error message telling me filelist isn't > defined. But now I'm kinda lost. > > If the directory holding the pics I want to work on is called > practicephotos, should I declare something along the lines of filelist = > ~/practicephotos/ or what? > > regards, Richard > > [code] > from PIL import Image > import os > > for infile in filelist: > outfile - os.path.splitext(infile)[0] + ".jpg" > if infile != outfile: > try: > Image.open(infile).save(outfile) > except IOError: > print "cannot convert", infile > [/code] > > As you have realized, the code is incomplete. The loop is expecting filelist to be already initialized to a list of strings, with each string being a filename. One way to get such a list (from the commandline) would be to use import sys filelist = sys.argv[1:] While I've got your attention, please send your messages here as plain text. The indentation of your html message is lost in the plain text version used in this forum. -- DaveA _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
