python in the future, you've seen the future can use the language version of the module do?

import xxx

from yy.xxx import xx

from yy.xxx import xx as x

The most common package python guide guide module statement

yy is the package name, the package is a folder, the file module is xxx.py

Today found a magic module __future__

The use python __future__

The new version of Python will introduce new features, but in fact these functions on an older version already exists. To "try" some new features, can be achieved by importing certain functions __future__ module.

For example, Python integer division integer result is still 2.7:

Unless coupled with a decimal point will become a decimal such as 0.05

>>> 10 / 3
3


>>> 10 / 3.0

3.33333333333

However, Python 3.x has improved integer division operation, "/" will be in addition to float, "//" In addition it still is an integer:

>>> 10 / 3
3.3333333333333335
>>> 10 // 3
3

3.x division rule to be introduced in Python 2.7, introducing the __future__ division:

>>> from __future__ import division
>>> print 10 / 3
3.3333333333333335

 

When a new version of a feature is not compatible with older versions, this feature will be added in the old version to __future__ so old code to test the new features in the old version.

What this means is that we in the case of the use of low version of the language, you can also use the new version only features, is really from the future module ah

 

Guess you like

Origin www.cnblogs.com/CYHISTW/p/10960595.html