2010-09-25 118 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.