blob: 6a1fdab5c57391505ab82a5d1ba88d1aa6ed4c1f [file] [log] [blame]
Georg Brandld3464752008-03-21 19:37:57 +00001:mod:`future_builtins` --- Python 3 builtins
2============================================
3
4.. module:: future_builtins
5.. sectionauthor:: Georg Brandl
6.. versionadded:: 2.6
7
8This module provides functions that exist in 2.x, but have different behavior in
9Python 3, so they cannot be put into the 2.x builtin namespace.
10
11Instead, if you want to write code compatible with Python 3 builtins, import
12them from this module, like this::
13
14 from future_builtins import map, filter
15
16 ... code using Python 3-style map and filter ...
17
Georg Brandl5a42ca62008-05-20 07:20:12 +000018The :term:`2to3` tool that ports Python 2 code to Python 3 will recognize
Georg Brandld3464752008-03-21 19:37:57 +000019this usage and leave the new builtins alone.
20
21.. note::
22
23 The Python 3 :func:`print` function is already in the builtins, but cannot be
24 accessed from Python 2 code unless you use the appropriate future statement::
25
26 from __future__ import print_function
27
28
29Available builtins are:
30
Georg Brandl89f48872008-06-11 18:55:38 +000031.. function:: ascii(object)
32
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
37 value.
38
Georg Brandld3464752008-03-21 19:37:57 +000039.. function:: filter(function, iterable)
40
41 Works like :func:`itertools.ifilter`.
42
43.. function:: hex(object)
44
45 Works like the builtin :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.
48
49.. function:: map(function, iterable, ...)
50
51 Works like :func:`itertools.imap`.
52
53.. function:: oct(object)
54
55 Works like the builtin :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 hexadecimal.
58
59.. function:: zip(*iterables)
60
61 Works like :func:`itertools.izip`.