I can catch at least two things: first a possible NameError at option 3 and second you are possibly eating an AttributeError exception.
A catch-all except clause is a code smell, it will mask the real cause of the error condition. Instead, try to limit the except to exceptions you are expecting or print the exception so it will hint you about the real problem.
Try this:
power = input()
if power == 1:
mode = "CONTOUR"
elif power == 2:
mode = 'EDGE_ENHANCE_MORE'
elif power == 3:
mode = "EDGE_ENHANCE"
else:
print "Wrong option"
try:
img = img.filter(getattr(ImageFilter, mode))
except Exception as e:
print "Ooops! Got a '{}' exception ({})".format(type(e), str(e))
else:
img.show()
[update]
when i tap 1, i won t compilator to use CONTOUR in place of mode,i get this kind of error: Traceback (most recent call last): File "./edytor.py", line 65, in img = img.filter(ImageFilter.mode) AttributeError: 'module' object has no attribute 'mode'
Yes, as I suspected. This will try to access a attribute called 'mode' in the ImageFilter module (and since the module has no mode attribute, you get the AttributeError):
ImageFilter.mode
You don't want that. Instead, you want ImageFilter.CONTOUR. So how do you call an attribute dynamically in Python if all you have is its name stored in a variable? Something like ImageFilter[mode] work in Javascript but not in Python. Well, easy enough, in Python you must use getattr:
getattr(ImageFilter, "CONTOUR")
EDGE_ENHANCEbetween quotes for the sake of coherence. Are you getting aNameErrorexception?