哪个版本的Python需要来自__未来__IMPORT WITH_STATEMENT?
问题描述
使用python2.6.5,我可以在不调用from __future__ import with_statement的情况下使用with语句。如果不专门从__future__导入,如何才能知道哪个版本的Python支持with?
解决方案
__future__功能是自我记录的。试试这个:
>>> from __future__ import with_statement
>>> with_statement.getOptionalRelease()
(2, 5, 0, 'alpha', 1)
>>> with_statement.getMandatoryRelease()
(2, 6, 0, 'alpha', 0)
分别表示支持from __future__ import with_statement的第一个版本和不支持from __future__的第一个版本。
另外,请阅读以下内容:
>>> import __future__
>>> help(__future__)
相关文章