0x1949 Team - FAZEMRX - MANAGER
Edit File: future_builtins.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> <title>28.4. future_builtins — Python 3 builtins — Python 2.7.18 documentation</title> <link rel="stylesheet" type="text/css" href="../_static/pygments.css" /> <link rel="stylesheet" type="text/css" href="../_static/classic.css" /> <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script> <script src="../_static/jquery.js"></script> <script src="../_static/underscore.js"></script> <script src="../_static/doctools.js"></script> <script src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.18 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="file:///usr/share/doc/python2.7/html/library/future_builtins.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;"> This document is for an old version of Python that is <a href="https://devguide.python.org/devcycle/#end-of-life-branches">no longer supported</a>. You should install the python3 and python3-doc packages and read the <a href="file:///usr/share/doc/python3-doc/html/library/future_builtins.html"> Python documentation for the Python3 version packaged in this release</a>. </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" 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> »</li> <li> <a href="../index.html">Python 2.7.18 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="python.html" accesskey="U"><span class="section-number">28. </span>Python Runtime Services</a> »</li> <li class="nav-item nav-item-this"><a href=""><span class="section-number">28.4. </span><code class="xref py py-mod docutils literal notranslate"><span class="pre">future_builtins</span></code> — Python 3 builtins</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <section id="module-future_builtins"> <span id="future-builtins-python-3-builtins"></span><h1><span class="section-number">28.4. </span><a class="reference internal" href="#module-future_builtins" title="future_builtins"><code class="xref py py-mod docutils literal notranslate"><span class="pre">future_builtins</span></code></a> — Python 3 builtins<a class="headerlink" href="#module-future_builtins" title="Permalink to this headline">¶</a></h1> <div class="versionadded"> <p><span class="versionmodified added">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 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">future_builtins</span> <span class="kn">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="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 notranslate"><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="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span> </pre></div> </div> </div> <p>Available builtins are:</p> <dl class="py function"> <dt class="sig sig-object py" id="future_builtins.ascii"> <span class="sig-prename descclassname"><span class="pre">future_builtins.</span></span><span class="sig-name descname"><span class="pre">ascii</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></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 notranslate"><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 notranslate"><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 notranslate"><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 notranslate"><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 notranslate"><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="py function"> <dt class="sig sig-object py" id="future_builtins.filter"> <span class="sig-prename descclassname"><span class="pre">future_builtins.</span></span><span class="sig-name descname"><span class="pre">filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iterable</span></span></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 notranslate"><span class="pre">itertools.ifilter()</span></code></a>.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="future_builtins.hex"> <span class="sig-prename descclassname"><span class="pre">future_builtins.</span></span><span class="sig-name descname"><span class="pre">hex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></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 notranslate"><span class="pre">hex()</span></code></a>, but instead of <code class="xref py py-meth docutils literal notranslate"><span class="pre">__hex__()</span></code> it will use the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code> method on its argument to get an integer that is then converted to hexadecimal.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="future_builtins.map"> <span class="sig-prename descclassname"><span class="pre">future_builtins.</span></span><span class="sig-name descname"><span class="pre">map</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iterable</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></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 notranslate"><span class="pre">itertools.imap()</span></code></a>.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>In Python 3, <a class="reference internal" href="functions.html#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a> does not accept <code class="docutils literal notranslate"><span class="pre">None</span></code> for the function argument.</p> </div> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="future_builtins.oct"> <span class="sig-prename descclassname"><span class="pre">future_builtins.</span></span><span class="sig-name descname"><span class="pre">oct</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">object</span></span></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 notranslate"><span class="pre">oct()</span></code></a>, but instead of <code class="xref py py-meth docutils literal notranslate"><span class="pre">__oct__()</span></code> it will use the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code> method on its argument to get an integer that is then converted to octal.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="future_builtins.zip"> <span class="sig-prename descclassname"><span class="pre">future_builtins.</span></span><span class="sig-name descname"><span class="pre">zip</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">iterables</span></span></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 notranslate"><span class="pre">itertools.izip()</span></code></a>.</p> </dd></dl> </section> <div class="clearer"></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"><span class="section-number">28.3. </span><code class="xref py py-mod docutils literal notranslate"><span class="pre">__builtin__</span></code> — Built-in objects</a></p> <h4>Next topic</h4> <p class="topless"><a href="__main__.html" title="next chapter"><span class="section-number">28.5. </span><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code> — Top-level script environment</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/library/future_builtins.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3 id="searchlabel">Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> <input type="submit" value="Go" /> </form> </div> </div> <script>$('#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> »</li> <li> <a href="../index.html">Python 2.7.18 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="python.html" ><span class="section-number">28. </span>Python Runtime Services</a> »</li> <li class="nav-item nav-item-this"><a href=""><span class="section-number">28.4. </span><code class="xref py py-mod docutils literal notranslate"><span class="pre">future_builtins</span></code> — Python 3 builtins</a></li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2024, 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 November 21, 2024. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 4.3.2. </div> </body> </html>