python __future__ module

       When I was looking at a code today, I suddenly found an unfamiliar module, the __future__ module, and then I went to the official website to check it and translated it. It is probably a module that has been tested and compatible with the new version of python in advance. Translate and understand , which roughly means:

       Each new version of Python adds some new functionality or makes some changes to the original functionality. Some changes are not compatible with the old version, that is, the code that runs normally in the current version may not run normally in the next version.

      There are some incompatible changes from Python 2.7 to Python 3.x. For example, strings in 2.x are used to 'xxx'represent str, and Unicode strings are used to u'xxx'represent unicode. In 3.x, all strings are treated as unicode. , therefore, the writing u'xxx'sum 'xxx'is exactly the same, and in 2.x, 'xxx'the str represented by it must be written b'xxx'as "binary string".

      Upgrading the code directly to 3.x is rather aggressive, because there are a lot of changes to test. On the contrary, you can test some 3.x features in a part of the code in the 2.7 version, and if there is no problem, it will be no later than porting to 3.x.

-------------------------------------------------- -----------------------------------Dividing line------------- -------------------------------------------------- -------------------------- There is a specific simple example to understand:

from __future__ import print_function

#python 2
print 'hello world'


#python 3
print('hello world')

If your python is python2, when you use the print() method of python3, you will find that it can also output normally

Some other examples:

from __future__ import division , 
from __future__ import absolute_import , 

from __future__ import with_statement