Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which python version needs from __future__ import with_statement?

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__?

like image 510
mlzboy Avatar asked Sep 25 '10 00:09

mlzboy


People also ask

What is import __ future __ in Python?

__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.

What is __ future __ import Absolute_import?

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.

What is from __ future __ import Print_function?

The main function of from __future__ import print_function is to bring the print function from Python 3 into Python 2.

What does future mean in Python?

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.


1 Answers

__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__) 
like image 70
Mark Tolonen Avatar answered Oct 18 '22 16:10

Mark Tolonen