What’s wrong with the “else” clause ?
for filename in files:
try:
im = Image.open(os.path.join(dirname,filename))
except IOError, e:
print "error opening file :: %s : %s" % (os.path.join(dirname,filename), e)
else:
print im.size
Now since you’re in a loop, you can also use a “continue” statement:
for filename in files:
try:
im = Image.open(os.path.join(dirname,filename))
except IOError, e:
print "error opening file :: %s : %s" % (os.path.join(dirname,filename), e)
continue
print im.size