“ else”子句有什么问题?
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
现在,由于您处于循环中,因此还可以使用“ continue”语句:
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