Time to read: 2 min read
I know it sounds crazy for the first time you heard. But it's real. Let's dig into this.
future module introduced from python 2.1. On the source of cpython's
__future__.py there is defined each future feature like following,
FeatureName = _Feature(OptionalRelease, MandatoryRelease, CompilerFlag)
Where, normally, OptionalRelease is less than MandatoryRelease, and both are 5-tuples of the same form as sys.version_info
sys.version_info(major=3, minor=8, micro=1, releaselevel='final', serial=0)
Suppose, you are using python2(Though python 2 is dead. Just take it an example). You want to use the print function from python3. But how you can do it? Here comes the future module.
Python 3 Console
>>> >>> print('Hello', 'World', sep=', ', end='\n') Hello, World >>> >>>
In python2 you need to do the following,
>>> >>> from __future__ import print_function >>> >>> print('Hello', 'World', sep=', ', end='\n') Hello, World >>>
Here, I have imported print_fuction from future module. Then it's working as expected from python3. I hope you got it.
See the source here
Good Luck 😃