Attention
This is copied verbatim from the old IPython wiki and is currently under development. Much of the information in this part of the development guide is out of date.
The IPython.utils.py3compat
module provides a number of functions to make it easier to write code for Python 2 and 3. We also use 2to3 in the setup process to change syntax, and the io.open()
function, which is essentially the built in open function from Python 3.
The names provided are:
raw_input
on Python 2, input
on Python 3 (needed because 2to3 only converts calls to raw_input, not assignments to other names).__builtin__
–> builtins
).codecs.open
, but allows universal newlines. The current implementation only supports the very simplest use.types.MethodType
from Python 3. Takes only two arguments: function, instance. The class argument for Python 2 is filled automatically.'{u}"thestring"'
, and fed to this function, which will produce 'u"thestring"'
for Python 2, and '"thestring"'
for Python 3. Can also be used as a decorator, to work on a docstring.