Changes to the language that may potentially break existing code are usually introduced gradually in Python. They often initially appear as optional extensions, which are disabled by default. To turn on such extensions, use a special import statement of this form:
from __future__ import featurename
When used in a script, this statement must appear as the first executable statement in the file (possibly following a docstring or comment), because it enables special compilation of code on a per-module basis. It’s also possible to submit this statement at the interactive prompt to experiment with upcoming language changes; the feature will then be available for the remainder of the interactive session.
For example, in this book we’ve seen how to use this statement in Python 2.X to activate 3.X true division in Chapter 5, 3.X print calls in Chapter 11, and 3.X absolute imports for packages in Chapter 24. Prior editions of this book used this statement form to demonstrate generator functions, which required a keyword that was not yet enabled by default (they use a featurename of generators).
All of these changes have the potential to break existing code in Python 2.X, so they were phased in gradually or offered as optional extensions, enabled with this special import. At the same time, some are available to allow you to write code that is forward compatible with later releases you may port to someday.
For a list of futurisms you may import and turn on this way, run a dir call on the __future__ module after importing it, or see its library manual entry. Per its documentation, none of its feature names will ever be removed, so it’s safe to leave in a __future__ import even in code run by a version of Python where the feature is present normally.