[Tutor] Pixelize ubuntu python script acting odd.
Tiger12506
keridee at jayco.net
Fri Feb 8 02:11:36 CET 2008
Some suggestions throughout
> def runThrough():
> walk = os.walk("/media/sda1/Documents/Pictures/2007") #location of the
> pics I want to use
> count = 0
> for root, dirs, files in walk:
> try:
> for x in files:
> if x.lower().find(".jpg")> -1: #If it's a .jpg...
This could be
if x.lower().endswith(".jpg"):
> count = count + 1
> operation = 'make_db ' + root + '/' + x
This could be also
operation = "make_db %s/%s" % (root,x)
> os.system(operation) # Call the command line with the
> operation above
> print root + '/' + x #This is optional, I did this for
> debugging
print "%s/%s" % (root,x)
> print str(count) + " files done"
print "%s files done" % count
> except OSError:
> print root + "/" + x + " was not included in the list"
> #This was run to get rid of all the obnoxious spaces in the file
> names
> #try:
> # for x in files:
> # loc = root + '/' + x
> # pic = loc.replace(' ', "_")
> # os.rename(loc, pic)
> # count = count + 1
> # print str(count) + "files done"
> #except OSError:
> # print root + '/' + x + " was not included"
I don't know much about ubuntu, so I can't answer the question. Also you
might consider os.path.join
And since you are doing this root+'/'+x so many times, perhaps you should
just assign it to a variable once
and use it instead? Say~ fullpath = root+'/'+x
More information about the Tutor
mailing list