1 :mod:`future_builtins` --- Python 3 built-ins
2 =============================================
4 .. module:: future_builtins
5 .. sectionauthor:: Georg Brandl
8 This module provides functions that exist in 2.x, but have different behavior in
9 Python 3, so they cannot be put into the 2.x builtins namespace.
11 Instead, if you want to write code compatible with Python 3 built-ins, import
12 them from this module, like this::
14 from future_builtins import map, filter
16 ... code using Python 3-style map and filter ...
18 The :term:`2to3` tool that ports Python 2 code to Python 3 will recognize
19 this usage and leave the new built-ins alone.
23 The Python 3 :func:`print` function is already in the built-ins, but cannot be
24 accessed from Python 2 code unless you use the appropriate future statement::
26 from __future__ import print_function
29 Available built-ins are:
31 .. function:: ascii(object)
33 Returns the same as :func:`repr`. In Python 3, :func:`repr` will return
34 printable Unicode characters unescaped, while :func:`ascii` will always
35 backslash-escape them. Using :func:`future_builtins.ascii` instead of
36 :func:`repr` in 2.6 code makes it clear that you need a pure ASCII return
39 .. function:: filter(function, iterable)
41 Works like :func:`itertools.ifilter`.
43 .. function:: hex(object)
45 Works like the built-in :func:`hex`, but instead of :meth:`__hex__` it will
46 use the :meth:`__index__` method on its argument to get an integer that is
47 then converted to hexadecimal.
49 .. function:: map(function, iterable, ...)
51 Works like :func:`itertools.imap`.
53 .. function:: oct(object)
55 Works like the built-in :func:`oct`, but instead of :meth:`__oct__` it will
56 use the :meth:`__index__` method on its argument to get an integer that is
57 then converted to octal.
59 .. function:: zip(*iterables)
61 Works like :func:`itertools.izip`.