可能重复:
Python try-else
我没有看到它的好处,至少基于我刚刚在 Dive Into Python 中阅读的示例:
try:
from EasyDialogs import AskPassword
except ImportError:
getpass = default_getpass
else:
getpass = AskPassword
( http://www.diveintopython.net/file_handling/index.html )
为什么你不能用更短/更简单的方式达到同样的效果:
try:
from EasyDialogs import AskPassword
getpass = AskPassword
except ImportError:
getpass = default_getpass
我错过了什么?