Sophie

Sophie

distrib > Mageia > 6 > armv5tl > by-pkgid > cd0177250baee0d27d6edc1f6af440ec > files > 792

python-docs-2.7.15-1.2.mga6.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>28.4. future_builtins — Python 3 builtins &#8212; Python 2.7.15 documentation</title>
    
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.7.15',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 2.7.15 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="next" title="28.5. __main__ — Top-level script environment" href="__main__.html" />
    <link rel="prev" title="28.3. __builtin__ — Built-in objects" href="__builtin__.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/2/library/future_builtins.html" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
 
    

  </head>
  <body role="document">  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="__main__.html" title="28.5. __main__ — Top-level script environment"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="__builtin__.html" title="28.3. __builtin__ — Built-in objects"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.15 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="python.html" accesskey="U">28. Python Runtime Services</a> &#187;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-future_builtins">
<span id="future-builtins-python-3-builtins"></span><h1>28.4. <a class="reference internal" href="#module-future_builtins" title="future_builtins"><code class="xref py py-mod docutils literal"><span class="pre">future_builtins</span></code></a> &#8212; Python 3 builtins<a class="headerlink" href="#module-future_builtins" title="Permalink to this headline">¶</a></h1>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.6.</span></p>
</div>
<p>This module provides functions that exist in 2.x, but have different behavior in
Python 3, so they cannot be put into the 2.x builtins namespace.</p>
<p>Instead, if you want to write code compatible with Python 3 builtins, import
them from this module, like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">future_builtins</span> <span class="k">import</span> <span class="nb">map</span><span class="p">,</span> <span class="nb">filter</span>

<span class="o">...</span> <span class="n">code</span> <span class="n">using</span> <span class="n">Python</span> <span class="mi">3</span><span class="o">-</span><span class="n">style</span> <span class="nb">map</span> <span class="ow">and</span> <span class="nb">filter</span> <span class="o">...</span>
</pre></div>
</div>
<p>The <a class="reference internal" href="../glossary.html#term-2to3"><span class="xref std std-term">2to3</span></a> tool that ports Python 2 code to Python 3 will recognize
this usage and leave the new builtins alone.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>The Python 3 <a class="reference internal" href="functions.html#print" title="print"><code class="xref py py-func docutils literal"><span class="pre">print()</span></code></a> function is already in the builtins, but cannot be
accessed from Python 2 code unless you use the appropriate future statement:</p>
<div class="last highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">print_function</span>
</pre></div>
</div>
</div>
<p>Available builtins are:</p>
<dl class="function">
<dt id="future_builtins.ascii">
<code class="descclassname">future_builtins.</code><code class="descname">ascii</code><span class="sig-paren">(</span><em>object</em><span class="sig-paren">)</span><a class="headerlink" href="#future_builtins.ascii" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the same as <a class="reference internal" href="functions.html#repr" title="repr"><code class="xref py py-func docutils literal"><span class="pre">repr()</span></code></a>.  In Python 3, <a class="reference internal" href="functions.html#repr" title="repr"><code class="xref py py-func docutils literal"><span class="pre">repr()</span></code></a> will return
printable Unicode characters unescaped, while <a class="reference internal" href="#future_builtins.ascii" title="future_builtins.ascii"><code class="xref py py-func docutils literal"><span class="pre">ascii()</span></code></a> will always
backslash-escape them.  Using <a class="reference internal" href="#future_builtins.ascii" title="future_builtins.ascii"><code class="xref py py-func docutils literal"><span class="pre">future_builtins.ascii()</span></code></a> instead of
<a class="reference internal" href="functions.html#repr" title="repr"><code class="xref py py-func docutils literal"><span class="pre">repr()</span></code></a> in 2.6 code makes it clear that you need a pure ASCII return
value.</p>
</dd></dl>

<dl class="function">
<dt id="future_builtins.filter">
<code class="descclassname">future_builtins.</code><code class="descname">filter</code><span class="sig-paren">(</span><em>function</em>, <em>iterable</em><span class="sig-paren">)</span><a class="headerlink" href="#future_builtins.filter" title="Permalink to this definition">¶</a></dt>
<dd><p>Works like <a class="reference internal" href="itertools.html#itertools.ifilter" title="itertools.ifilter"><code class="xref py py-func docutils literal"><span class="pre">itertools.ifilter()</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="future_builtins.hex">
<code class="descclassname">future_builtins.</code><code class="descname">hex</code><span class="sig-paren">(</span><em>object</em><span class="sig-paren">)</span><a class="headerlink" href="#future_builtins.hex" title="Permalink to this definition">¶</a></dt>
<dd><p>Works like the built-in <a class="reference internal" href="functions.html#hex" title="hex"><code class="xref py py-func docutils literal"><span class="pre">hex()</span></code></a>, but instead of <a class="reference internal" href="../reference/datamodel.html#object.__hex__" title="object.__hex__"><code class="xref py py-meth docutils literal"><span class="pre">__hex__()</span></code></a> it will
use the <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal"><span class="pre">__index__()</span></code></a> method on its argument to get an integer that is
then converted to hexadecimal.</p>
</dd></dl>

<dl class="function">
<dt id="future_builtins.map">
<code class="descclassname">future_builtins.</code><code class="descname">map</code><span class="sig-paren">(</span><em>function</em>, <em>iterable</em>, <em>...</em><span class="sig-paren">)</span><a class="headerlink" href="#future_builtins.map" title="Permalink to this definition">¶</a></dt>
<dd><p>Works like <a class="reference internal" href="itertools.html#itertools.imap" title="itertools.imap"><code class="xref py py-func docutils literal"><span class="pre">itertools.imap()</span></code></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">In Python 3, <a class="reference internal" href="functions.html#map" title="map"><code class="xref py py-func docutils literal"><span class="pre">map()</span></code></a> does not accept <code class="docutils literal"><span class="pre">None</span></code> for the
function argument.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="future_builtins.oct">
<code class="descclassname">future_builtins.</code><code class="descname">oct</code><span class="sig-paren">(</span><em>object</em><span class="sig-paren">)</span><a class="headerlink" href="#future_builtins.oct" title="Permalink to this definition">¶</a></dt>
<dd><p>Works like the built-in <a class="reference internal" href="functions.html#oct" title="oct"><code class="xref py py-func docutils literal"><span class="pre">oct()</span></code></a>, but instead of <a class="reference internal" href="../reference/datamodel.html#object.__oct__" title="object.__oct__"><code class="xref py py-meth docutils literal"><span class="pre">__oct__()</span></code></a> it will
use the <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal"><span class="pre">__index__()</span></code></a> method on its argument to get an integer that is
then converted to octal.</p>
</dd></dl>

<dl class="function">
<dt id="future_builtins.zip">
<code class="descclassname">future_builtins.</code><code class="descname">zip</code><span class="sig-paren">(</span><em>*iterables</em><span class="sig-paren">)</span><a class="headerlink" href="#future_builtins.zip" title="Permalink to this definition">¶</a></dt>
<dd><p>Works like <a class="reference internal" href="itertools.html#itertools.izip" title="itertools.izip"><code class="xref py py-func docutils literal"><span class="pre">itertools.izip()</span></code></a>.</p>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="__builtin__.html"
                        title="previous chapter">28.3. <code class="docutils literal"><span class="pre">__builtin__</span></code> &#8212; Built-in objects</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="__main__.html"
                        title="next chapter">28.5. <code class="docutils literal"><span class="pre">__main__</span></code> &#8212; Top-level script environment</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="https://github.com/python/cpython/blob/2.7/Doc/library/future_builtins.rst"
         rel="nofollow">Show Source</a>
  </li>
</ul>

<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="__main__.html" title="28.5. __main__ — Top-level script environment"
             >next</a> |</li>
        <li class="right" >
          <a href="__builtin__.html" title="28.3. __builtin__ — Built-in objects"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.15 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="python.html" >28. Python Runtime Services</a> &#187;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2018, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Apr 29, 2018.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.5.6.
    </div>

  </body>
</html>