哪种方法对于在特定版本的python中导入模块最有意义?我的用例是我正在编写将部署到Python 2.3环境中的代码,并在几个月内升级到python 2.5。这:导入特定于版本的python模块的最佳方法
if sys.version_info[:2] >= (2, 5):
from string import Template
else:
from our.compat.string import Template
或本
try:
from string import Template
except ImportError:
from our.compat.string import Template
我知道,这两种情况下是同样正确和工作正常,但哪一个是最好?
你已经错过了`从xml.etree进口cElementTree作为ET`为Python 2.5和高达 – jfs 2008-12-05 00:42:37