1The ``futurize`` script passes Python 2 code through all the appropriate fixers
2to turn it into valid Python 3 code, and then adds ``__future__`` and
3``future`` package imports to re-enable compatibility with Python 2.
4
5For example, running ``futurize`` turns this Python 2 code:
6
7.. code-block:: python
8
9    import ConfigParser                 # Py2 module name
10
11    class Upper(object):
12        def __init__(self, iterable):
13            self._iter = iter(iterable)
14        def next(self):                 # Py2-style iterator interface
15            return next(self._iter).upper()
16        def __iter__(self):
17            return self
18
19    itr = Upper('hello')
20    print next(itr),
21    for letter in itr:
22        print letter,                   # Py2-style print statement
23
24into this code which runs on both Py2 and Py3:
25
26.. code-block:: python
27
28    from __future__ import print_function
29    from future import standard_library
30    standard_library.install_aliases()
31    from future.builtins import next
32    from future.builtins import object
33    import configparser                 # Py3-style import
34
35    class Upper(object):
36        def __init__(self, iterable):
37            self._iter = iter(iterable)
38        def __next__(self):             # Py3-style iterator interface
39            return next(self._iter).upper()
40        def __iter__(self):
41            return self
42
43    itr = Upper('hello')
44    print(next(itr), end=' ')           # Py3-style print function
45    for letter in itr:
46        print(letter, end=' ')
47
48
49To write out all the changes to your Python files that ``futurize`` suggests,
50use the ``-w`` flag.
51
52For complex projects, it is probably best to divide the porting into two stages.
53Stage 1 is for "safe" changes that modernize the code but do not break Python
542.7 compatibility or introduce a dependency on the ``future`` package. Stage 2
55is to complete the process.
56