|
Original |
Translation |
|
25
|
Since some print statements can be parsed as function calls or statements, 2to3 cannot always read files containing the print function. When 2to3 detects the presence of the ``from __future__ import print_function`` compiler directive, it modifies its internal grammar to interpert :func:`print` as a function. This change can also be enabled manually with the :option:`-p` flag. Use :option:`-p` to run fixers on code that already has had its print statements converted.
|
|
|
26
|
|
|
|
27
|
Each step of transforming code is encapsulated in a fixer. The command ``2to3 -l`` lists them. As :ref:`documented above <2to3-using>`, each can be turned on and off individually. They are described here in more detail.
|
|
|
28
|
Removes usage of :func:`apply`. For example ``apply(function, *args, **kwargs)`` is converted to ``function(*args, **kwargs)``.
|
|
|
29
|
Converts :class:`basestring` to :class:`str`.
|
|
|
30
|
|
31
|
Converts ``callable(x)`` to ``isinstance(x, collections.Callable)``, adding an import to :mod:`collections` if needed.
|
|
|
32
|
Fixes dictionary iteration methods. :meth:`dict.iteritems` is converted to :meth:`dict.items`, :meth:`dict.iterkeys` to :meth:`dict.keys`, and :meth:`dict.itervalues` to :meth:`dict.values`. Similarly, :meth:`dict.viewitems`, :meth:`dict.viewkeys` and :meth:`dict.viewvalues` are converted respectively to :meth:`dict.items`, :meth:`dict.keys` and :meth:`dict.values`. It also wraps existing usages of :meth:`dict.items`, :meth:`dict.keys`, and :meth:`dict.values` in a call to :class:`list`.
|
|
|
33
|
Converts ``except X, T`` to ``except X as T``.
|
|
|
34
|
Converts the :keyword:`exec` statement to the :func:`exec` function.
|
|