有的版本并不支持所需要的模块,这时需要根据 Python 的版本对导入进行处理
处理的时候要用到 ImportError 异常
- try:
-
import subprocess
-
except ImportError, e:
-
if sys.version_info <= (2, 3):
-
print 'ERROR: %s' % e
-
print 'ERROR: this script requires Python 2.4 or greater; or at least the subprocess module.'
-
print 'If you copy subprocess.py from a newer version of Python this script will probably work'
-
sys.exit(101)
-
else:
-
raise
阅读(1104) | 评论(0) | 转发(0) |