Python – Which Version Requires from __future__ import with_statement?

pythonpython-import

Using python 2.6.5, I can use the with statement without calling from __future__ import with_statement. How can I tell which version of Python supports with without specifically importing it from __future__?

Best Answer

__future__ features are self-documenting. Try this:

>>> from __future__ import with_statement
>>> with_statement.getOptionalRelease()
(2, 5, 0, 'alpha', 1)
>>> with_statement.getMandatoryRelease()
(2, 6, 0, 'alpha', 0)

These respectively indicate the first release supporting from __future__ import with_statement and the first release to support it without using from __future__.

Also, read this:

>>> import __future__
>>> help(__future__)