我试图捕捉无法加载模块时发生的任何异常。当前的结果是“except”块没有被执行。
import sys
def loadModule(module):
try:
import module
except:
print """
Cannot load %s
For this script you will need:
cx_Oracle: http://cx-oracle.sourceforge.net/
pycrypto: https://www.dlitz.net/software/pycrypto/
paramiko: http://www.lag.net/paramiko/
""" % module
sys.exit(1)
loadModule(cx_Oracle)
错误:
Traceback (most recent call last):
File "./temp_script.py", line 16, in <module>
loadModule(cx_Oracle)
NameError: name 'cx_Oracle' is not defined