__future__ in Python
In Python, if you want to use a future version of Python in a certain version of Python, you can use the following syntax:
from __future__ import futurename
This statement must be placed on the first line of the module file.
For example, if you want to use the print function of Python 3.X in Python 2.X, you only need to add the first line of the module file:
from __future__ import print_function
However, how to know what futurenames are? One method is as follows:
import __future__ #Import __future module dir( __future__ ) #List the attributes in the __future__ module [ ' with_statement ' , ' print_function ' , ' absolute_import ' ...]