There are already several __future__ answers, but none of them contain a complete list of what the __future__ operator currently supports.
Simply put, the __future__ statement forces Python interpreters to take advantage of new language features.
It currently supports the following features:
nested_scopes :
Prior to Python 2.1, the following code would throw a NameError error :
def f(): ... def g(value): ... return g(value-1) + 1 ...
from __future__ import nested_scopes will enable this function.
generators :
Generator functions have been introduced, such as the one below, to maintain state between successive function calls:
def fib(): a, b = 0, 1 while 1: yield b a, b = b, a+b
division :
The classic split is used in versions of Python 2.x. This means that some division operators return a reasonable approximation to division ("true division"), while others return the word ("division by gender"). Starting in Python 3.0, true division is defined as x/y , while gender division is defined as x//y .
from __future__ import division forces the use of Python 3.0 style partitioning.
absolute_import :
Enables you to bracket multiple import statements. For example:
from Tkinter import (Tk, Frame, Button, Entry, Canvas, Text, LEFT, DISABLED, NORMAL, RIDGE, END)
Instead:
from Tkinter import Tk, Frame, Button, Entry, Canvas, Text, \ LEFT, DISABLED, NORMAL, RIDGE, END
Or:
from Tkinter import Tk, Frame, Button, Entry, Canvas, Text from Tkinter import LEFT, DISABLED, NORMAL, RIDGE, END
with_statement :
Adds a "with" statement as a keyword in Python to eliminate the need for try/finally . This is usually used when performing file I / O, for example:
with open('workfile', 'r') as f: read_data = f.read()
print_function :
Forcing the use of the print function call to the Python 3 style brackets instead of the print MESSAGE statement print MESSAGE style.
unicode_literals :
Introduces the literal syntax for the bytes object. This means that expressions such as bytes('Hello world', 'ascii') can simply be expressed as b'Hello world' .
generator_stop :
Replaces the use of the StopIteration exception used within the generator functions with a RuntimeError exception.
Another use not mentioned above is that the __future__ operator also causes the use of Python __future__ interpreters. 1+, since using an older version will throw a runtime exception.
Recommendations: