2010-09-25 117 views

回答

45

__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__) 
16

你只需要Python 2.5。旧版本(< = 2.4)不支持它,而较新版本(> = 2.6)默认启用它。

所以如果你想支持Python> = 2.5,你可以简单地把from __future__ import with_statement放在开头。对于较新的版本,它将被忽略。

1

从DOC:

New in version 2.5.