About the __future__ module in python

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.

Specifically, a new feature appears in a certain version, and this feature is incompatible with the one used in the current version, that is, it is not a language standard in this version, then if I want to use it, I need to Import from future module. There was no future before version 2.1, so using it will throw an exception. Of course, in a later version, say 3, a feature has become part of the standard, so you don't need to import it from future to use that feature.

事例:from _future_ import absolute_import

Relative import in python module, absolute import

Relative import: import the module of your own package without specifying the package name. For example, there are two files test1.py and test2.py under a package. In test1.py, from . import test2 is relative import test2.py .
Absolute import: specify the top-level package name. For example, import paname, Python will look for all top-level modules named paname in sys.path.

from __future__ import absolute_import: The future statement necessary to enable features such as relative imports in older versions prior to 3.0.
---------------------
Author: prettysky123
Source: CSDN
Original text: https://blog.csdn.net/prettysky123/article/details/80970199
Copyright statement: This article Original articles for bloggers, please attach a link to the blog post for reprinting!