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__
?
__future__ module is a built-in module in Python that is used to inherit new features that will be available in the new Python versions.. This module includes all the latest functions which were not present in the previous version in Python. And we can use this by importing the __future__ module.
from __future__ import absolute_import means that if you import string , Python will always look for a top-level string module, rather than current_package.string . However, it does not affect the logic Python uses to decide what file is the string module.
The main function of from __future__ import print_function is to bring the print function from Python 3 into Python 2.
A future statement is a directive to the compiler that a particular module should be compiled using syntax or semantics that will be available in a specified future release of Python. The future statement is intended to ease migration to future versions of Python that introduce incompatible changes to the language.
__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__)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With