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__
?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
__future__
features are self-documenting. Try this:These respectively indicate the first release supporting
from __future__ import with_statement
and the first release to support it without usingfrom __future__
.Also, read this:
You only need it in Python 2.5. Older versions (<= 2.4) don't support it and newer versions (>= 2.6) have it enabled by default.
So if you want to support Python >= 2.5, you can simply put the
from __future__ import with_statement
at the beginning. For newer versions, it will simply be ignored.From the doc: