Chinaunix首页 | 论坛 | 博客
  • 博客访问: 38611
  • 博文数量: 11
  • 博客积分: 265
  • 博客等级: 二等列兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-18 21:14
文章分类

全部博文(11)

文章存档

2012年(4)

2011年(7)

我的朋友

分类: Python/Ruby

2011-11-18 21:30:54

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


阅读(1066) | 评论(0) | 转发(0) |
0

上一篇:Tips (更新中)

下一篇:virtualenv

给主人留下些什么吧!~~