# Handle all the exceptions!
#Setup
actor = {"name": "John Cleese", "rank": "awesome"}
def get_last_name():
try:
return actor["last_name"]
except KeyError:
return "Cleese"
#Test code
get_last_name()
print "All exceptions caught! Good job!"
print "The actor's last name is %s" % get_last_name()
Hi guys, could you please tell me why I got this error:
Traceback (most recent call last):
File "/base/data/home/apps/s~learnpythonjail/3.368780930138799213/main.py", line 77, in execute_python
exec(code, {})
File "<string>", line 9
except SyntaxError:
^
SyntaxError: invalid syntax
I tried all types of error catching and it still produces a syntax error.
Thanks a lot for any help!
except SyntaxError:. There is probably a missing parenthesis or bracket on the preceding line.except SyntaxError:line is part of the code for whatever tutorial tool he's using ("learnpythonjail" is suggestive) and not something the OP wrote.