# 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()
大家好,请告诉我为什么会出现这个错误:
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
我尝试了所有类型的错误捕获,它仍然会产生语法错误。
非常感谢您的帮助!