2009-12-20 11:23:22 -04:00
|
|
|
:mod:`future_builtins` --- Python 3 builtins
|
|
|
|
============================================
|
2008-03-21 16:37:57 -03:00
|
|
|
|
|
|
|
.. module:: future_builtins
|
|
|
|
.. sectionauthor:: Georg Brandl
|
|
|
|
.. versionadded:: 2.6
|
|
|
|
|
|
|
|
This module provides functions that exist in 2.x, but have different behavior in
|
2009-07-26 11:37:28 -03:00
|
|
|
Python 3, so they cannot be put into the 2.x builtins namespace.
|
2008-03-21 16:37:57 -03:00
|
|
|
|
2009-12-20 11:23:22 -04:00
|
|
|
Instead, if you want to write code compatible with Python 3 builtins, import
|
2008-03-21 16:37:57 -03:00
|
|
|
them from this module, like this::
|
|
|
|
|
|
|
|
from future_builtins import map, filter
|
|
|
|
|
|
|
|
... code using Python 3-style map and filter ...
|
|
|
|
|
2008-05-20 04:20:12 -03:00
|
|
|
The :term:`2to3` tool that ports Python 2 code to Python 3 will recognize
|
2009-12-20 11:23:22 -04:00
|
|
|
this usage and leave the new builtins alone.
|
2008-03-21 16:37:57 -03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2009-12-20 11:23:22 -04:00
|
|
|
The Python 3 :func:`print` function is already in the builtins, but cannot be
|
2008-03-21 16:37:57 -03:00
|
|
|
accessed from Python 2 code unless you use the appropriate future statement::
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
|
2009-12-20 11:23:22 -04:00
|
|
|
Available builtins are:
|
2008-03-21 16:37:57 -03:00
|
|
|
|
2008-06-11 15:55:38 -03:00
|
|
|
.. function:: ascii(object)
|
|
|
|
|
|
|
|
Returns the same as :func:`repr`. In Python 3, :func:`repr` will return
|
|
|
|
printable Unicode characters unescaped, while :func:`ascii` will always
|
|
|
|
backslash-escape them. Using :func:`future_builtins.ascii` instead of
|
|
|
|
:func:`repr` in 2.6 code makes it clear that you need a pure ASCII return
|
|
|
|
value.
|
|
|
|
|
2008-03-21 16:37:57 -03:00
|
|
|
.. function:: filter(function, iterable)
|
|
|
|
|
|
|
|
Works like :func:`itertools.ifilter`.
|
|
|
|
|
|
|
|
.. function:: hex(object)
|
|
|
|
|
2009-07-26 11:37:28 -03:00
|
|
|
Works like the built-in :func:`hex`, but instead of :meth:`__hex__` it will
|
2008-03-21 16:37:57 -03:00
|
|
|
use the :meth:`__index__` method on its argument to get an integer that is
|
|
|
|
then converted to hexadecimal.
|
|
|
|
|
|
|
|
.. function:: map(function, iterable, ...)
|
|
|
|
|
|
|
|
Works like :func:`itertools.imap`.
|
|
|
|
|
2014-03-09 16:01:09 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
In Python 3, :func:`map` does not accept ``None`` for the
|
|
|
|
function argument.
|
|
|
|
|
2008-03-21 16:37:57 -03:00
|
|
|
.. function:: oct(object)
|
|
|
|
|
2009-07-26 11:37:28 -03:00
|
|
|
Works like the built-in :func:`oct`, but instead of :meth:`__oct__` it will
|
2008-03-21 16:37:57 -03:00
|
|
|
use the :meth:`__index__` method on its argument to get an integer that is
|
2009-04-04 03:39:56 -03:00
|
|
|
then converted to octal.
|
2008-03-21 16:37:57 -03:00
|
|
|
|
|
|
|
.. function:: zip(*iterables)
|
|
|
|
|
|
|
|
Works like :func:`itertools.izip`.
|