add files
This commit is contained in:
1224
python-3.7.4-docs-html/whatsnew/2.0.html
Normal file
1224
python-3.7.4-docs-html/whatsnew/2.0.html
Normal file
File diff suppressed because it is too large
Load Diff
913
python-3.7.4-docs-html/whatsnew/2.1.html
Normal file
913
python-3.7.4-docs-html/whatsnew/2.1.html
Normal file
@@ -0,0 +1,913 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>What’s New in Python 2.1 — Python 3.7.4 documentation</title>
|
||||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></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/language_data.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
||||
|
||||
<link rel="search" type="application/opensearchdescription+xml"
|
||||
title="Search within Python 3.7.4 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="What’s New in Python 2.0" href="2.0.html" />
|
||||
<link rel="prev" title="What’s New in Python 2.2" href="2.2.html" />
|
||||
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
|
||||
<link rel="canonical" href="https://docs.python.org/3/whatsnew/2.1.html" />
|
||||
|
||||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||||
<script type="text/javascript" src="../_static/switchers.js"></script>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
@media only screen {
|
||||
table.full-width-table {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
</head><body>
|
||||
|
||||
<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="2.0.html" title="What’s New in Python 2.0"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="2.2.html" title="What’s New in Python 2.2"
|
||||
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>
|
||||
<span class="language_switcher_placeholder">en</span>
|
||||
<span class="version_switcher_placeholder">3.7.4</span>
|
||||
<a href="../index.html">Documentation </a> »
|
||||
</li>
|
||||
|
||||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> »</li>
|
||||
<li class="right">
|
||||
|
||||
|
||||
<div class="inline-search" style="display: none" role="search">
|
||||
<form class="inline-search" action="../search.html" method="get">
|
||||
<input placeholder="Quick search" type="text" name="q" />
|
||||
<input type="submit" value="Go" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||||
|
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="what-s-new-in-python-2-1">
|
||||
<h1>What’s New in Python 2.1<a class="headerlink" href="#what-s-new-in-python-2-1" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Author</dt>
|
||||
<dd class="field-odd"><p>A.M. Kuchling</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<div class="section" id="introduction">
|
||||
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This article explains the new features in Python 2.1. While there aren’t as
|
||||
many changes in 2.1 as there were in Python 2.0, there are still some pleasant
|
||||
surprises in store. 2.1 is the first release to be steered through the use of
|
||||
Python Enhancement Proposals, or PEPs, so most of the sizable changes have
|
||||
accompanying PEPs that provide more complete documentation and a design
|
||||
rationale for the change. This article doesn’t attempt to document the new
|
||||
features completely, but simply provides an overview of the new features for
|
||||
Python programmers. Refer to the Python 2.1 documentation, or to the specific
|
||||
PEP, for more details about any new feature that particularly interests you.</p>
|
||||
<p>One recent goal of the Python development team has been to accelerate the pace
|
||||
of new releases, with a new release coming every 6 to 9 months. 2.1 is the first
|
||||
release to come out at this faster pace, with the first alpha appearing in
|
||||
January, 3 months after the final version of 2.0 was released.</p>
|
||||
<p>The final release of Python 2.1 was made on April 17, 2001.</p>
|
||||
</div>
|
||||
<div class="section" id="pep-227-nested-scopes">
|
||||
<h2>PEP 227: Nested Scopes<a class="headerlink" href="#pep-227-nested-scopes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The largest change in Python 2.1 is to Python’s scoping rules. In Python 2.0,
|
||||
at any given time there are at most three namespaces used to look up variable
|
||||
names: local, module-level, and the built-in namespace. This often surprised
|
||||
people because it didn’t match their intuitive expectations. For example, a
|
||||
nested recursive function definition doesn’t work:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
|
||||
<span class="o">...</span>
|
||||
<span class="k">def</span> <span class="nf">g</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
<span class="k">return</span> <span class="n">g</span><span class="p">(</span><span class="n">value</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The function <code class="xref py py-func docutils literal notranslate"><span class="pre">g()</span></code> will always raise a <a class="reference internal" href="../library/exceptions.html#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a> exception, because
|
||||
the binding of the name <code class="docutils literal notranslate"><span class="pre">g</span></code> isn’t in either its local namespace or in the
|
||||
module-level namespace. This isn’t much of a problem in practice (how often do
|
||||
you recursively define interior functions like this?), but this also made using
|
||||
the <a class="reference internal" href="../reference/expressions.html#lambda"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">lambda</span></code></a> expression clumsier, and this was a problem in practice.
|
||||
In code which uses <a class="reference internal" href="../reference/expressions.html#lambda"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">lambda</span></code></a> you can often find local variables being
|
||||
copied by passing them as the default values of arguments.</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">find</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
|
||||
<span class="s2">"Return list of any entries equal to 'name'"</span>
|
||||
<span class="n">L</span> <span class="o">=</span> <span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">:</span> <span class="n">x</span> <span class="o">==</span> <span class="n">name</span><span class="p">,</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">list_attribute</span><span class="p">)</span>
|
||||
<span class="k">return</span> <span class="n">L</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The readability of Python code written in a strongly functional style suffers
|
||||
greatly as a result.</p>
|
||||
<p>The most significant change to Python 2.1 is that static scoping has been added
|
||||
to the language to fix this problem. As a first effect, the <code class="docutils literal notranslate"><span class="pre">name=name</span></code>
|
||||
default argument is now unnecessary in the above example. Put simply, when a
|
||||
given variable name is not assigned a value within a function (by an assignment,
|
||||
or the <a class="reference internal" href="../reference/compound_stmts.html#def"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">def</span></code></a>, <a class="reference internal" href="../reference/compound_stmts.html#class"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">class</span></code></a>, or <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> statements),
|
||||
references to the variable will be looked up in the local namespace of the
|
||||
enclosing scope. A more detailed explanation of the rules, and a dissection of
|
||||
the implementation, can be found in the PEP.</p>
|
||||
<p>This change may cause some compatibility problems for code where the same
|
||||
variable name is used both at the module level and as a local variable within a
|
||||
function that contains further function definitions. This seems rather unlikely
|
||||
though, since such code would have been pretty confusing to read in the first
|
||||
place.</p>
|
||||
<p>One side effect of the change is that the <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">module</span> <span class="pre">import</span> <span class="pre">*</span></code> and
|
||||
<code class="docutils literal notranslate"><span class="pre">exec</span></code> statements have been made illegal inside a function scope under
|
||||
certain conditions. The Python reference manual has said all along that <code class="docutils literal notranslate"><span class="pre">from</span>
|
||||
<span class="pre">module</span> <span class="pre">import</span> <span class="pre">*</span></code> is only legal at the top level of a module, but the CPython
|
||||
interpreter has never enforced this before. As part of the implementation of
|
||||
nested scopes, the compiler which turns Python source into bytecodes has to
|
||||
generate different code to access variables in a containing scope. <code class="docutils literal notranslate"><span class="pre">from</span>
|
||||
<span class="pre">module</span> <span class="pre">import</span> <span class="pre">*</span></code> and <code class="docutils literal notranslate"><span class="pre">exec</span></code> make it impossible for the compiler to
|
||||
figure this out, because they add names to the local namespace that are
|
||||
unknowable at compile time. Therefore, if a function contains function
|
||||
definitions or <a class="reference internal" href="../reference/expressions.html#lambda"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">lambda</span></code></a> expressions with free variables, the compiler
|
||||
will flag this by raising a <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> exception.</p>
|
||||
<p>To make the preceding explanation a bit clearer, here’s an example:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
|
||||
<span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
|
||||
<span class="c1"># The next line is a syntax error</span>
|
||||
<span class="n">exec</span> <span class="s1">'x=2'</span>
|
||||
<span class="k">def</span> <span class="nf">g</span><span class="p">():</span>
|
||||
<span class="k">return</span> <span class="n">x</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Line 4 containing the <code class="docutils literal notranslate"><span class="pre">exec</span></code> statement is a syntax error, since
|
||||
<code class="docutils literal notranslate"><span class="pre">exec</span></code> would define a new local variable named <code class="docutils literal notranslate"><span class="pre">x</span></code> whose value should
|
||||
be accessed by <code class="xref py py-func docutils literal notranslate"><span class="pre">g()</span></code>.</p>
|
||||
<p>This shouldn’t be much of a limitation, since <code class="docutils literal notranslate"><span class="pre">exec</span></code> is rarely used in
|
||||
most Python code (and when it is used, it’s often a sign of a poor design
|
||||
anyway).</p>
|
||||
<p>Compatibility concerns have led to nested scopes being introduced gradually; in
|
||||
Python 2.1, they aren’t enabled by default, but can be turned on within a module
|
||||
by using a future statement as described in PEP 236. (See the following section
|
||||
for further discussion of PEP 236.) In Python 2.2, nested scopes will become
|
||||
the default and there will be no way to turn them off, but users will have had
|
||||
all of 2.1’s lifetime to fix any breakage resulting from their introduction.</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0227"><strong>PEP 227</strong></a> - Statically Nested Scopes</dt><dd><p>Written and implemented by Jeremy Hylton.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-236-future-directives">
|
||||
<h2>PEP 236: __future__ Directives<a class="headerlink" href="#pep-236-future-directives" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The reaction to nested scopes was widespread concern about the dangers of
|
||||
breaking code with the 2.1 release, and it was strong enough to make the
|
||||
Pythoneers take a more conservative approach. This approach consists of
|
||||
introducing a convention for enabling optional functionality in release N that
|
||||
will become compulsory in release N+1.</p>
|
||||
<p>The syntax uses a <code class="docutils literal notranslate"><span class="pre">from...import</span></code> statement using the reserved module name
|
||||
<a class="reference internal" href="../library/__future__.html#module-__future__" title="__future__: Future statement definitions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">__future__</span></code></a>. Nested scopes can be enabled by the following statement:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">nested_scopes</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>While it looks like a normal <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> statement, it’s not; there are
|
||||
strict rules on where such a future statement can be put. They can only be at
|
||||
the top of a module, and must precede any Python code or regular
|
||||
<code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code> statements. This is because such statements can affect how
|
||||
the Python bytecode compiler parses code and generates bytecode, so they must
|
||||
precede any statement that will result in bytecodes being produced.</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0236"><strong>PEP 236</strong></a> - Back to the <a class="reference internal" href="../library/__future__.html#module-__future__" title="__future__: Future statement definitions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">__future__</span></code></a></dt><dd><p>Written by Tim Peters, and primarily implemented by Jeremy Hylton.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-207-rich-comparisons">
|
||||
<h2>PEP 207: Rich Comparisons<a class="headerlink" href="#pep-207-rich-comparisons" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In earlier versions, Python’s support for implementing comparisons on user-defined
|
||||
classes and extension types was quite simple. Classes could implement a
|
||||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">__cmp__()</span></code> method that was given two instances of a class, and could only
|
||||
return 0 if they were equal or +1 or -1 if they weren’t; the method couldn’t
|
||||
raise an exception or return anything other than a Boolean value. Users of
|
||||
Numeric Python often found this model too weak and restrictive, because in the
|
||||
number-crunching programs that numeric Python is used for, it would be more
|
||||
useful to be able to perform elementwise comparisons of two matrices, returning
|
||||
a matrix containing the results of a given comparison for each element. If the
|
||||
two matrices are of different sizes, then the compare has to be able to raise an
|
||||
exception to signal the error.</p>
|
||||
<p>In Python 2.1, rich comparisons were added in order to support this need.
|
||||
Python classes can now individually overload each of the <code class="docutils literal notranslate"><span class="pre"><</span></code>, <code class="docutils literal notranslate"><span class="pre"><=</span></code>, <code class="docutils literal notranslate"><span class="pre">></span></code>,
|
||||
<code class="docutils literal notranslate"><span class="pre">>=</span></code>, <code class="docutils literal notranslate"><span class="pre">==</span></code>, and <code class="docutils literal notranslate"><span class="pre">!=</span></code> operations. The new magic method names are:</p>
|
||||
<table class="docutils align-center">
|
||||
<colgroup>
|
||||
<col style="width: 41%" />
|
||||
<col style="width: 59%" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="row-odd"><th class="head"><p>Operation</p></th>
|
||||
<th class="head"><p>Method name</p></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre"><</span></code></p></td>
|
||||
<td><p><a class="reference internal" href="../reference/datamodel.html#object.__lt__" title="object.__lt__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__lt__()</span></code></a></p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre"><=</span></code></p></td>
|
||||
<td><p><a class="reference internal" href="../reference/datamodel.html#object.__le__" title="object.__le__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__le__()</span></code></a></p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">></span></code></p></td>
|
||||
<td><p><a class="reference internal" href="../reference/datamodel.html#object.__gt__" title="object.__gt__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__gt__()</span></code></a></p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">>=</span></code></p></td>
|
||||
<td><p><a class="reference internal" href="../reference/datamodel.html#object.__ge__" title="object.__ge__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__ge__()</span></code></a></p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">==</span></code></p></td>
|
||||
<td><p><a class="reference internal" href="../reference/datamodel.html#object.__eq__" title="object.__eq__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__eq__()</span></code></a></p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">!=</span></code></p></td>
|
||||
<td><p><a class="reference internal" href="../reference/datamodel.html#object.__ne__" title="object.__ne__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__ne__()</span></code></a></p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>(The magic methods are named after the corresponding Fortran operators <code class="docutils literal notranslate"><span class="pre">.LT.</span></code>.
|
||||
<code class="docutils literal notranslate"><span class="pre">.LE.</span></code>, &c. Numeric programmers are almost certainly quite familiar with
|
||||
these names and will find them easy to remember.)</p>
|
||||
<p>Each of these magic methods is of the form <code class="docutils literal notranslate"><span class="pre">method(self,</span> <span class="pre">other)</span></code>, where
|
||||
<code class="docutils literal notranslate"><span class="pre">self</span></code> will be the object on the left-hand side of the operator, while
|
||||
<code class="docutils literal notranslate"><span class="pre">other</span></code> will be the object on the right-hand side. For example, the
|
||||
expression <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre"><</span> <span class="pre">B</span></code> will cause <code class="docutils literal notranslate"><span class="pre">A.__lt__(B)</span></code> to be called.</p>
|
||||
<p>Each of these magic methods can return anything at all: a Boolean, a matrix, a
|
||||
list, or any other Python object. Alternatively they can raise an exception if
|
||||
the comparison is impossible, inconsistent, or otherwise meaningless.</p>
|
||||
<p>The built-in <code class="docutils literal notranslate"><span class="pre">cmp(A,B)</span></code> function can use the rich comparison machinery,
|
||||
and now accepts an optional argument specifying which comparison operation to
|
||||
use; this is given as one of the strings <code class="docutils literal notranslate"><span class="pre">"<"</span></code>, <code class="docutils literal notranslate"><span class="pre">"<="</span></code>, <code class="docutils literal notranslate"><span class="pre">">"</span></code>, <code class="docutils literal notranslate"><span class="pre">">="</span></code>,
|
||||
<code class="docutils literal notranslate"><span class="pre">"=="</span></code>, or <code class="docutils literal notranslate"><span class="pre">"!="</span></code>. If called without the optional third argument,
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">cmp()</span></code> will only return -1, 0, or +1 as in previous versions of Python;
|
||||
otherwise it will call the appropriate method and can return any Python object.</p>
|
||||
<p>There are also corresponding changes of interest to C programmers; there’s a new
|
||||
slot <code class="docutils literal notranslate"><span class="pre">tp_richcmp</span></code> in type objects and an API for performing a given rich
|
||||
comparison. I won’t cover the C API here, but will refer you to PEP 207, or to
|
||||
2.1’s C API documentation, for the full list of related functions.</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0207"><strong>PEP 207</strong></a> - Rich Comparisons</dt><dd><p>Written by Guido van Rossum, heavily based on earlier work by David Ascher, and
|
||||
implemented by Guido van Rossum.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-230-warning-framework">
|
||||
<h2>PEP 230: Warning Framework<a class="headerlink" href="#pep-230-warning-framework" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Over its 10 years of existence, Python has accumulated a certain number of
|
||||
obsolete modules and features along the way. It’s difficult to know when a
|
||||
feature is safe to remove, since there’s no way of knowing how much code uses it
|
||||
— perhaps no programs depend on the feature, or perhaps many do. To enable
|
||||
removing old features in a more structured way, a warning framework was added.
|
||||
When the Python developers want to get rid of a feature, it will first trigger a
|
||||
warning in the next version of Python. The following Python version can then
|
||||
drop the feature, and users will have had a full release cycle to remove uses of
|
||||
the old feature.</p>
|
||||
<p>Python 2.1 adds the warning framework to be used in this scheme. It adds a
|
||||
<a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module that provide functions to issue warnings, and to filter
|
||||
out warnings that you don’t want to be displayed. Third-party modules can also
|
||||
use this framework to deprecate old features that they no longer wish to
|
||||
support.</p>
|
||||
<p>For example, in Python 2.1 the <code class="xref py py-mod docutils literal notranslate"><span class="pre">regex</span></code> module is deprecated, so importing
|
||||
it causes a warning to be printed:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">regex</span>
|
||||
<span class="go">__main__:1: DeprecationWarning: the regex module</span>
|
||||
<span class="go"> is deprecated; please use the re module</span>
|
||||
<span class="go">>>></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Warnings can be issued by calling the <a class="reference internal" href="../library/warnings.html#warnings.warn" title="warnings.warn"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.warn()</span></code></a> function:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">"feature X no longer supported"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The first parameter is the warning message; an additional optional parameters
|
||||
can be used to specify a particular warning category.</p>
|
||||
<p>Filters can be added to disable certain warnings; a regular expression pattern
|
||||
can be applied to the message or to the module name in order to suppress a
|
||||
warning. For example, you may have a program that uses the <code class="xref py py-mod docutils literal notranslate"><span class="pre">regex</span></code> module
|
||||
and not want to spare the time to convert it to use the <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a> module right
|
||||
now. The warning can be suppressed by calling</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">warnings</span>
|
||||
<span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="n">action</span> <span class="o">=</span> <span class="s1">'ignore'</span><span class="p">,</span>
|
||||
<span class="n">message</span><span class="o">=</span><span class="s1">'.*regex module is deprecated'</span><span class="p">,</span>
|
||||
<span class="n">category</span><span class="o">=</span><span class="ne">DeprecationWarning</span><span class="p">,</span>
|
||||
<span class="n">module</span> <span class="o">=</span> <span class="s1">'__main__'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>This adds a filter that will apply only to warnings of the class
|
||||
<a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-class docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> triggered in the <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where the top-level script is run."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module, and applies
|
||||
a regular expression to only match the message about the <code class="xref py py-mod docutils literal notranslate"><span class="pre">regex</span></code> module
|
||||
being deprecated, and will cause such warnings to be ignored. Warnings can also
|
||||
be printed only once, printed every time the offending code is executed, or
|
||||
turned into exceptions that will cause the program to stop (unless the
|
||||
exceptions are caught in the usual way, of course).</p>
|
||||
<p>Functions were also added to Python’s C API for issuing warnings; refer to PEP
|
||||
230 or to Python’s API documentation for the details.</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-3"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0005"><strong>PEP 5</strong></a> - Guidelines for Language Evolution</dt><dd><p>Written by Paul Prescod, to specify procedures to be followed when removing old
|
||||
features from Python. The policy described in this PEP hasn’t been officially
|
||||
adopted, but the eventual policy probably won’t be too different from Prescod’s
|
||||
proposal.</p>
|
||||
</dd>
|
||||
<dt><span class="target" id="index-4"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0230"><strong>PEP 230</strong></a> - Warning Framework</dt><dd><p>Written and implemented by Guido van Rossum.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-229-new-build-system">
|
||||
<h2>PEP 229: New Build System<a class="headerlink" href="#pep-229-new-build-system" title="Permalink to this headline">¶</a></h2>
|
||||
<p>When compiling Python, the user had to go in and edit the <code class="file docutils literal notranslate"><span class="pre">Modules/Setup</span></code>
|
||||
file in order to enable various additional modules; the default set is
|
||||
relatively small and limited to modules that compile on most Unix platforms.
|
||||
This means that on Unix platforms with many more features, most notably Linux,
|
||||
Python installations often don’t contain all useful modules they could.</p>
|
||||
<p>Python 2.0 added the Distutils, a set of modules for distributing and installing
|
||||
extensions. In Python 2.1, the Distutils are used to compile much of the
|
||||
standard library of extension modules, autodetecting which ones are supported on
|
||||
the current machine. It’s hoped that this will make Python installations easier
|
||||
and more featureful.</p>
|
||||
<p>Instead of having to edit the <code class="file docutils literal notranslate"><span class="pre">Modules/Setup</span></code> file in order to enable
|
||||
modules, a <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> script in the top directory of the Python source
|
||||
distribution is run at build time, and attempts to discover which modules can be
|
||||
enabled by examining the modules and header files on the system. If a module is
|
||||
configured in <code class="file docutils literal notranslate"><span class="pre">Modules/Setup</span></code>, the <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> script won’t attempt
|
||||
to compile that module and will defer to the <code class="file docutils literal notranslate"><span class="pre">Modules/Setup</span></code> file’s
|
||||
contents. This provides a way to specific any strange command-line flags or
|
||||
libraries that are required for a specific platform.</p>
|
||||
<p>In another far-reaching change to the build mechanism, Neil Schemenauer
|
||||
restructured things so Python now uses a single makefile that isn’t recursive,
|
||||
instead of makefiles in the top directory and in each of the <code class="file docutils literal notranslate"><span class="pre">Python/</span></code>,
|
||||
<code class="file docutils literal notranslate"><span class="pre">Parser/</span></code>, <code class="file docutils literal notranslate"><span class="pre">Objects/</span></code>, and <code class="file docutils literal notranslate"><span class="pre">Modules/</span></code> subdirectories. This
|
||||
makes building Python faster and also makes hacking the Makefiles clearer and
|
||||
simpler.</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-5"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0229"><strong>PEP 229</strong></a> - Using Distutils to Build Python</dt><dd><p>Written and implemented by A.M. Kuchling.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-205-weak-references">
|
||||
<h2>PEP 205: Weak References<a class="headerlink" href="#pep-205-weak-references" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Weak references, available through the <a class="reference internal" href="../library/weakref.html#module-weakref" title="weakref: Support for weak references and weak dictionaries."><code class="xref py py-mod docutils literal notranslate"><span class="pre">weakref</span></code></a> module, are a minor but
|
||||
useful new data type in the Python programmer’s toolbox.</p>
|
||||
<p>Storing a reference to an object (say, in a dictionary or a list) has the side
|
||||
effect of keeping that object alive forever. There are a few specific cases
|
||||
where this behaviour is undesirable, object caches being the most common one,
|
||||
and another being circular references in data structures such as trees.</p>
|
||||
<p>For example, consider a memoizing function that caches the results of another
|
||||
function <code class="docutils literal notranslate"><span class="pre">f(x)</span></code> by storing the function’s argument and its result in a
|
||||
dictionary:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">_cache</span> <span class="o">=</span> <span class="p">{}</span>
|
||||
<span class="k">def</span> <span class="nf">memoize</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
|
||||
<span class="k">if</span> <span class="n">_cache</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
|
||||
<span class="k">return</span> <span class="n">_cache</span><span class="p">[</span><span class="n">x</span><span class="p">]</span>
|
||||
|
||||
<span class="n">retval</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
|
||||
|
||||
<span class="c1"># Cache the returned object</span>
|
||||
<span class="n">_cache</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">retval</span>
|
||||
|
||||
<span class="k">return</span> <span class="n">retval</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>This version works for simple things such as integers, but it has a side effect;
|
||||
the <code class="docutils literal notranslate"><span class="pre">_cache</span></code> dictionary holds a reference to the return values, so they’ll
|
||||
never be deallocated until the Python process exits and cleans up. This isn’t
|
||||
very noticeable for integers, but if <code class="xref py py-func docutils literal notranslate"><span class="pre">f()</span></code> returns an object, or a data
|
||||
structure that takes up a lot of memory, this can be a problem.</p>
|
||||
<p>Weak references provide a way to implement a cache that won’t keep objects alive
|
||||
beyond their time. If an object is only accessible through weak references, the
|
||||
object will be deallocated and the weak references will now indicate that the
|
||||
object it referred to no longer exists. A weak reference to an object <em>obj</em> is
|
||||
created by calling <code class="docutils literal notranslate"><span class="pre">wr</span> <span class="pre">=</span> <span class="pre">weakref.ref(obj)</span></code>. The object being referred to is
|
||||
returned by calling the weak reference as if it were a function: <code class="docutils literal notranslate"><span class="pre">wr()</span></code>. It
|
||||
will return the referenced object, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the object no longer exists.</p>
|
||||
<p>This makes it possible to write a <code class="xref py py-func docutils literal notranslate"><span class="pre">memoize()</span></code> function whose cache doesn’t
|
||||
keep objects alive, by storing weak references in the cache.</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">_cache</span> <span class="o">=</span> <span class="p">{}</span>
|
||||
<span class="k">def</span> <span class="nf">memoize</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
|
||||
<span class="k">if</span> <span class="n">_cache</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
|
||||
<span class="n">obj</span> <span class="o">=</span> <span class="n">_cache</span><span class="p">[</span><span class="n">x</span><span class="p">]()</span>
|
||||
<span class="c1"># If weak reference object still exists,</span>
|
||||
<span class="c1"># return it</span>
|
||||
<span class="k">if</span> <span class="n">obj</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> <span class="k">return</span> <span class="n">obj</span>
|
||||
|
||||
<span class="n">retval</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
|
||||
|
||||
<span class="c1"># Cache a weak reference</span>
|
||||
<span class="n">_cache</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">weakref</span><span class="o">.</span><span class="n">ref</span><span class="p">(</span><span class="n">retval</span><span class="p">)</span>
|
||||
|
||||
<span class="k">return</span> <span class="n">retval</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The <a class="reference internal" href="../library/weakref.html#module-weakref" title="weakref: Support for weak references and weak dictionaries."><code class="xref py py-mod docutils literal notranslate"><span class="pre">weakref</span></code></a> module also allows creating proxy objects which behave like
|
||||
weak references — an object referenced only by proxy objects is deallocated –
|
||||
but instead of requiring an explicit call to retrieve the object, the proxy
|
||||
transparently forwards all operations to the object as long as the object still
|
||||
exists. If the object is deallocated, attempting to use a proxy will cause a
|
||||
<a class="reference internal" href="../library/weakref.html#weakref.ReferenceError" title="weakref.ReferenceError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">weakref.ReferenceError</span></code></a> exception to be raised.</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">proxy</span> <span class="o">=</span> <span class="n">weakref</span><span class="o">.</span><span class="n">proxy</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
|
||||
<span class="n">proxy</span><span class="o">.</span><span class="n">attr</span> <span class="c1"># Equivalent to obj.attr</span>
|
||||
<span class="n">proxy</span><span class="o">.</span><span class="n">meth</span><span class="p">()</span> <span class="c1"># Equivalent to obj.meth()</span>
|
||||
<span class="k">del</span> <span class="n">obj</span>
|
||||
<span class="n">proxy</span><span class="o">.</span><span class="n">attr</span> <span class="c1"># raises weakref.ReferenceError</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-6"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0205"><strong>PEP 205</strong></a> - Weak References</dt><dd><p>Written and implemented by Fred L. Drake, Jr.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-232-function-attributes">
|
||||
<h2>PEP 232: Function Attributes<a class="headerlink" href="#pep-232-function-attributes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>In Python 2.1, functions can now have arbitrary information attached to them.
|
||||
People were often using docstrings to hold information about functions and
|
||||
methods, because the <code class="docutils literal notranslate"><span class="pre">__doc__</span></code> attribute was the only way of attaching any
|
||||
information to a function. For example, in the Zope Web application server,
|
||||
functions are marked as safe for public access by having a docstring, and in
|
||||
John Aycock’s SPARK parsing framework, docstrings hold parts of the BNF grammar
|
||||
to be parsed. This overloading is unfortunate, since docstrings are really
|
||||
intended to hold a function’s documentation; for example, it means you can’t
|
||||
properly document functions intended for private use in Zope.</p>
|
||||
<p>Arbitrary attributes can now be set and retrieved on functions using the regular
|
||||
Python syntax:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">f</span><span class="p">():</span> <span class="k">pass</span>
|
||||
|
||||
<span class="n">f</span><span class="o">.</span><span class="n">publish</span> <span class="o">=</span> <span class="mi">1</span>
|
||||
<span class="n">f</span><span class="o">.</span><span class="n">secure</span> <span class="o">=</span> <span class="mi">1</span>
|
||||
<span class="n">f</span><span class="o">.</span><span class="n">grammar</span> <span class="o">=</span> <span class="s2">"A ::= B (C D)*"</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The dictionary containing attributes can be accessed as the function’s
|
||||
<a class="reference internal" href="../library/stdtypes.html#object.__dict__" title="object.__dict__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__dict__</span></code></a>. Unlike the <a class="reference internal" href="../library/stdtypes.html#object.__dict__" title="object.__dict__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__dict__</span></code></a> attribute of class instances, in
|
||||
functions you can actually assign a new dictionary to <a class="reference internal" href="../library/stdtypes.html#object.__dict__" title="object.__dict__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__dict__</span></code></a>, though
|
||||
the new value is restricted to a regular Python dictionary; you <em>can’t</em> be
|
||||
tricky and set it to a <code class="xref py py-class docutils literal notranslate"><span class="pre">UserDict</span></code> instance, or any other random object
|
||||
that behaves like a mapping.</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-7"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0232"><strong>PEP 232</strong></a> - Function Attributes</dt><dd><p>Written and implemented by Barry Warsaw.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-235-importing-modules-on-case-insensitive-platforms">
|
||||
<h2>PEP 235: Importing Modules on Case-Insensitive Platforms<a class="headerlink" href="#pep-235-importing-modules-on-case-insensitive-platforms" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Some operating systems have filesystems that are case-insensitive, MacOS and
|
||||
Windows being the primary examples; on these systems, it’s impossible to
|
||||
distinguish the filenames <code class="docutils literal notranslate"><span class="pre">FILE.PY</span></code> and <code class="docutils literal notranslate"><span class="pre">file.py</span></code>, even though they do store
|
||||
the file’s name in its original case (they’re case-preserving, too).</p>
|
||||
<p>In Python 2.1, the <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> statement will work to simulate case-sensitivity
|
||||
on case-insensitive platforms. Python will now search for the first
|
||||
case-sensitive match by default, raising an <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> if no such file
|
||||
is found, so <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">file</span></code> will not import a module named <code class="docutils literal notranslate"><span class="pre">FILE.PY</span></code>.
|
||||
Case-insensitive matching can be requested by setting the <span class="target" id="index-8"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONCASEOK"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONCASEOK</span></code></a>
|
||||
environment variable before starting the Python interpreter.</p>
|
||||
</div>
|
||||
<div class="section" id="pep-217-interactive-display-hook">
|
||||
<h2>PEP 217: Interactive Display Hook<a class="headerlink" href="#pep-217-interactive-display-hook" title="Permalink to this headline">¶</a></h2>
|
||||
<p>When using the Python interpreter interactively, the output of commands is
|
||||
displayed using the built-in <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> function. In Python 2.1, the variable
|
||||
<a class="reference internal" href="../library/sys.html#sys.displayhook" title="sys.displayhook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.displayhook()</span></code></a> can be set to a callable object which will be called
|
||||
instead of <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a>. For example, you can set it to a special
|
||||
pretty-printing function:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># Create a recursive data structure</span>
|
||||
<span class="gp">... </span><span class="n">L</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">]</span>
|
||||
<span class="gp">>>> </span><span class="n">L</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">L</span><span class="p">)</span>
|
||||
<span class="gp">>>> </span><span class="n">L</span> <span class="c1"># Show Python's default output</span>
|
||||
<span class="go">[1, 2, 3, [...]]</span>
|
||||
<span class="gp">>>> </span><span class="c1"># Use pprint.pprint() as the display function</span>
|
||||
<span class="gp">... </span><span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">pprint</span>
|
||||
<span class="gp">>>> </span><span class="n">sys</span><span class="o">.</span><span class="n">displayhook</span> <span class="o">=</span> <span class="n">pprint</span><span class="o">.</span><span class="n">pprint</span>
|
||||
<span class="gp">>>> </span><span class="n">L</span>
|
||||
<span class="go">[1, 2, 3, <Recursion on list with id=135143996>]</span>
|
||||
<span class="go">>>></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-9"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0217"><strong>PEP 217</strong></a> - Display Hook for Interactive Use</dt><dd><p>Written and implemented by Moshe Zadka.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-208-new-coercion-model">
|
||||
<h2>PEP 208: New Coercion Model<a class="headerlink" href="#pep-208-new-coercion-model" title="Permalink to this headline">¶</a></h2>
|
||||
<p>How numeric coercion is done at the C level was significantly modified. This
|
||||
will only affect the authors of C extensions to Python, allowing them more
|
||||
flexibility in writing extension types that support numeric operations.</p>
|
||||
<p>Extension types can now set the type flag <code class="docutils literal notranslate"><span class="pre">Py_TPFLAGS_CHECKTYPES</span></code> in their
|
||||
<code class="docutils literal notranslate"><span class="pre">PyTypeObject</span></code> structure to indicate that they support the new coercion model.
|
||||
In such extension types, the numeric slot functions can no longer assume that
|
||||
they’ll be passed two arguments of the same type; instead they may be passed two
|
||||
arguments of differing types, and can then perform their own internal coercion.
|
||||
If the slot function is passed a type it can’t handle, it can indicate the
|
||||
failure by returning a reference to the <code class="docutils literal notranslate"><span class="pre">Py_NotImplemented</span></code> singleton value.
|
||||
The numeric functions of the other type will then be tried, and perhaps they can
|
||||
handle the operation; if the other type also returns <code class="docutils literal notranslate"><span class="pre">Py_NotImplemented</span></code>, then
|
||||
a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> will be raised. Numeric methods written in Python can also
|
||||
return <code class="docutils literal notranslate"><span class="pre">Py_NotImplemented</span></code>, causing the interpreter to act as if the method
|
||||
did not exist (perhaps raising a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>, perhaps trying another
|
||||
object’s numeric methods).</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-10"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0208"><strong>PEP 208</strong></a> - Reworking the Coercion Model</dt><dd><p>Written and implemented by Neil Schemenauer, heavily based upon earlier work by
|
||||
Marc-André Lemburg. Read this to understand the fine points of how numeric
|
||||
operations will now be processed at the C level.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-241-metadata-in-python-packages">
|
||||
<h2>PEP 241: Metadata in Python Packages<a class="headerlink" href="#pep-241-metadata-in-python-packages" title="Permalink to this headline">¶</a></h2>
|
||||
<p>A common complaint from Python users is that there’s no single catalog of all
|
||||
the Python modules in existence. T. Middleton’s Vaults of Parnassus at
|
||||
<a class="reference external" href="http://www.vex.net/parnassus/">http://www.vex.net/parnassus/</a> are the largest catalog of Python modules, but
|
||||
registering software at the Vaults is optional, and many people don’t bother.</p>
|
||||
<p>As a first small step toward fixing the problem, Python software packaged using
|
||||
the Distutils <strong class="command">sdist</strong> command will include a file named
|
||||
<code class="file docutils literal notranslate"><span class="pre">PKG-INFO</span></code> containing information about the package such as its name,
|
||||
version, and author (metadata, in cataloguing terminology). PEP 241 contains
|
||||
the full list of fields that can be present in the <code class="file docutils literal notranslate"><span class="pre">PKG-INFO</span></code> file. As
|
||||
people began to package their software using Python 2.1, more and more packages
|
||||
will include metadata, making it possible to build automated cataloguing systems
|
||||
and experiment with them. With the result experience, perhaps it’ll be possible
|
||||
to design a really good catalog and then build support for it into Python 2.2.
|
||||
For example, the Distutils <strong class="command">sdist</strong> and <strong class="command">bdist_*</strong> commands
|
||||
could support an <code class="docutils literal notranslate"><span class="pre">upload</span></code> option that would automatically upload your
|
||||
package to a catalog server.</p>
|
||||
<p>You can start creating packages containing <code class="file docutils literal notranslate"><span class="pre">PKG-INFO</span></code> even if you’re not
|
||||
using Python 2.1, since a new release of the Distutils will be made for users of
|
||||
earlier Python versions. Version 1.0.2 of the Distutils includes the changes
|
||||
described in PEP 241, as well as various bugfixes and enhancements. It will be
|
||||
available from the Distutils SIG at <a class="reference external" href="https://www.python.org/community/sigs/current/distutils-sig/">https://www.python.org/community/sigs/current/distutils-sig/</a>.</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-11"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0241"><strong>PEP 241</strong></a> - Metadata for Python Software Packages</dt><dd><p>Written and implemented by A.M. Kuchling.</p>
|
||||
</dd>
|
||||
<dt><span class="target" id="index-12"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0243"><strong>PEP 243</strong></a> - Module Repository Upload Mechanism</dt><dd><p>Written by Sean Reifschneider, this draft PEP describes a proposed mechanism for
|
||||
uploading Python packages to a central server.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="new-and-improved-modules">
|
||||
<h2>New and Improved Modules<a class="headerlink" href="#new-and-improved-modules" title="Permalink to this headline">¶</a></h2>
|
||||
<ul>
|
||||
<li><p>Ka-Ping Yee contributed two new modules: <code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect.py</span></code>, a module for
|
||||
getting information about live Python code, and <code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc.py</span></code>, a module for
|
||||
interactively converting docstrings to HTML or text. As a bonus,
|
||||
<code class="file docutils literal notranslate"><span class="pre">Tools/scripts/pydoc</span></code>, which is now automatically installed, uses
|
||||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc.py</span></code> to display documentation given a Python module, package, or
|
||||
class name. For example, <code class="docutils literal notranslate"><span class="pre">pydoc</span> <span class="pre">xml.dom</span></code> displays the following:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Python</span> <span class="n">Library</span> <span class="n">Documentation</span><span class="p">:</span> <span class="n">package</span> <span class="n">xml</span><span class="o">.</span><span class="n">dom</span> <span class="ow">in</span> <span class="n">xml</span>
|
||||
|
||||
<span class="n">NAME</span>
|
||||
<span class="n">xml</span><span class="o">.</span><span class="n">dom</span> <span class="o">-</span> <span class="n">W3C</span> <span class="n">Document</span> <span class="n">Object</span> <span class="n">Model</span> <span class="n">implementation</span> <span class="k">for</span> <span class="n">Python</span><span class="o">.</span>
|
||||
|
||||
<span class="n">FILE</span>
|
||||
<span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">local</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">python2</span><span class="o">.</span><span class="mi">1</span><span class="o">/</span><span class="n">xml</span><span class="o">/</span><span class="n">dom</span><span class="o">/</span><span class="fm">__init__</span><span class="o">.</span><span class="n">pyc</span>
|
||||
|
||||
<span class="n">DESCRIPTION</span>
|
||||
<span class="n">The</span> <span class="n">Python</span> <span class="n">mapping</span> <span class="n">of</span> <span class="n">the</span> <span class="n">Document</span> <span class="n">Object</span> <span class="n">Model</span> <span class="ow">is</span> <span class="n">documented</span> <span class="ow">in</span> <span class="n">the</span>
|
||||
<span class="n">Python</span> <span class="n">Library</span> <span class="n">Reference</span> <span class="ow">in</span> <span class="n">the</span> <span class="n">section</span> <span class="n">on</span> <span class="n">the</span> <span class="n">xml</span><span class="o">.</span><span class="n">dom</span> <span class="n">package</span><span class="o">.</span>
|
||||
|
||||
<span class="n">This</span> <span class="n">package</span> <span class="n">contains</span> <span class="n">the</span> <span class="n">following</span> <span class="n">modules</span><span class="p">:</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p><code class="file docutils literal notranslate"><span class="pre">pydoc</span></code> also includes a Tk-based interactive help browser. <code class="file docutils literal notranslate"><span class="pre">pydoc</span></code>
|
||||
quickly becomes addictive; try it out!</p>
|
||||
</li>
|
||||
<li><p>Two different modules for unit testing were added to the standard library.
|
||||
The <a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> module, contributed by Tim Peters, provides a testing
|
||||
framework based on running embedded examples in docstrings and comparing the
|
||||
results against the expected output. PyUnit, contributed by Steve Purcell, is a
|
||||
unit testing framework inspired by JUnit, which was in turn an adaptation of
|
||||
Kent Beck’s Smalltalk testing framework. See <a class="reference external" href="http://pyunit.sourceforge.net/">http://pyunit.sourceforge.net/</a> for
|
||||
more information about PyUnit.</p></li>
|
||||
<li><p>The <a class="reference internal" href="../library/difflib.html#module-difflib" title="difflib: Helpers for computing differences between objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">difflib</span></code></a> module contains a class, <code class="xref py py-class docutils literal notranslate"><span class="pre">SequenceMatcher</span></code>, which
|
||||
compares two sequences and computes the changes required to transform one
|
||||
sequence into the other. For example, this module can be used to write a tool
|
||||
similar to the Unix <strong class="program">diff</strong> program, and in fact the sample program
|
||||
<code class="file docutils literal notranslate"><span class="pre">Tools/scripts/ndiff.py</span></code> demonstrates how to write such a script.</p></li>
|
||||
<li><p><a class="reference internal" href="../library/curses.panel.html#module-curses.panel" title="curses.panel: A panel stack extension that adds depth to curses windows."><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses.panel</span></code></a>, a wrapper for the panel library, part of ncurses and of
|
||||
SYSV curses, was contributed by Thomas Gellekum. The panel library provides
|
||||
windows with the additional feature of depth. Windows can be moved higher or
|
||||
lower in the depth ordering, and the panel library figures out where panels
|
||||
overlap and which sections are visible.</p></li>
|
||||
<li><p>The PyXML package has gone through a few releases since Python 2.0, and Python
|
||||
2.1 includes an updated version of the <a class="reference internal" href="../library/xml.html#module-xml" title="xml: Package containing XML processing modules"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml</span></code></a> package. Some of the
|
||||
noteworthy changes include support for Expat 1.2 and later versions, the ability
|
||||
for Expat parsers to handle files in any encoding supported by Python, and
|
||||
various bugfixes for SAX, DOM, and the <code class="xref py py-mod docutils literal notranslate"><span class="pre">minidom</span></code> module.</p></li>
|
||||
<li><p>Ping also contributed another hook for handling uncaught exceptions.
|
||||
<a class="reference internal" href="../library/sys.html#sys.excepthook" title="sys.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.excepthook()</span></code></a> can be set to a callable object. When an exception isn’t
|
||||
caught by any <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">try</span></code></a>…<a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> blocks, the exception will be
|
||||
passed to <a class="reference internal" href="../library/sys.html#sys.excepthook" title="sys.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.excepthook()</span></code></a>, which can then do whatever it likes. At the
|
||||
Ninth Python Conference, Ping demonstrated an application for this hook:
|
||||
printing an extended traceback that not only lists the stack frames, but also
|
||||
lists the function arguments and the local variables for each frame.</p></li>
|
||||
<li><p>Various functions in the <a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> module, such as <code class="xref py py-func docutils literal notranslate"><span class="pre">asctime()</span></code> and
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code>, require a floating point argument containing the time in
|
||||
seconds since the epoch. The most common use of these functions is to work with
|
||||
the current time, so the floating point argument has been made optional; when a
|
||||
value isn’t provided, the current time will be used. For example, log file
|
||||
entries usually need a string containing the current time; in Python 2.1,
|
||||
<code class="docutils literal notranslate"><span class="pre">time.asctime()</span></code> can be used, instead of the lengthier
|
||||
<code class="docutils literal notranslate"><span class="pre">time.asctime(time.localtime(time.time()))</span></code> that was previously required.</p>
|
||||
<p>This change was proposed and implemented by Thomas Wouters.</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a> module now defaults to retrieving files in passive mode,
|
||||
because passive mode is more likely to work from behind a firewall. This
|
||||
request came from the Debian bug tracking system, since other Debian packages
|
||||
use <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a> to retrieve files and then don’t work from behind a firewall.
|
||||
It’s deemed unlikely that this will cause problems for anyone, because Netscape
|
||||
defaults to passive mode and few people complain, but if passive mode is
|
||||
unsuitable for your application or network setup, call <code class="docutils literal notranslate"><span class="pre">set_pasv(0)</span></code> on
|
||||
FTP objects to disable passive mode.</p></li>
|
||||
<li><p>Support for raw socket access has been added to the <a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a> module,
|
||||
contributed by Grant Edwards.</p></li>
|
||||
<li><p>The <a class="reference internal" href="../library/profile.html#module-pstats" title="pstats: Statistics object for use with the profiler."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pstats</span></code></a> module now contains a simple interactive statistics browser
|
||||
for displaying timing profiles for Python programs, invoked when the module is
|
||||
run as a script. Contributed by Eric S. Raymond.</p></li>
|
||||
<li><p>A new implementation-dependent function, <code class="docutils literal notranslate"><span class="pre">sys._getframe([depth])</span></code>, has
|
||||
been added to return a given frame object from the current call stack.
|
||||
<a class="reference internal" href="../library/sys.html#sys._getframe" title="sys._getframe"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys._getframe()</span></code></a> returns the frame at the top of the call stack; if the
|
||||
optional integer argument <em>depth</em> is supplied, the function returns the frame
|
||||
that is <em>depth</em> calls below the top of the stack. For example,
|
||||
<code class="docutils literal notranslate"><span class="pre">sys._getframe(1)</span></code> returns the caller’s frame object.</p>
|
||||
<p>This function is only present in CPython, not in Jython or the .NET
|
||||
implementation. Use it for debugging, and resist the temptation to put it into
|
||||
production code.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="other-changes-and-fixes">
|
||||
<h2>Other Changes and Fixes<a class="headerlink" href="#other-changes-and-fixes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>There were relatively few smaller changes made in Python 2.1 due to the shorter
|
||||
release cycle. A search through the CVS change logs turns up 117 patches
|
||||
applied, and 136 bugs fixed; both figures are likely to be underestimates. Some
|
||||
of the more notable changes are:</p>
|
||||
<ul>
|
||||
<li><p>A specialized object allocator is now optionally available, that should be
|
||||
faster than the system <code class="xref py py-func docutils literal notranslate"><span class="pre">malloc()</span></code> and have less memory overhead. The
|
||||
allocator uses C’s <code class="xref py py-func docutils literal notranslate"><span class="pre">malloc()</span></code> function to get large pools of memory, and
|
||||
then fulfills smaller memory requests from these pools. It can be enabled by
|
||||
providing the <code class="xref std std-option docutils literal notranslate"><span class="pre">--with-pymalloc</span></code> option to the <strong class="program">configure</strong>
|
||||
script; see <code class="file docutils literal notranslate"><span class="pre">Objects/obmalloc.c</span></code> for the implementation details.</p>
|
||||
<p>Authors of C extension modules should test their code with the object allocator
|
||||
enabled, because some incorrect code may break, causing core dumps at runtime.
|
||||
There are a bunch of memory allocation functions in Python’s C API that have
|
||||
previously been just aliases for the C library’s <code class="xref py py-func docutils literal notranslate"><span class="pre">malloc()</span></code> and
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">free()</span></code>, meaning that if you accidentally called mismatched functions, the
|
||||
error wouldn’t be noticeable. When the object allocator is enabled, these
|
||||
functions aren’t aliases of <code class="xref py py-func docutils literal notranslate"><span class="pre">malloc()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">free()</span></code> any more, and
|
||||
calling the wrong function to free memory will get you a core dump. For
|
||||
example, if memory was allocated using <code class="xref py py-func docutils literal notranslate"><span class="pre">PyMem_New()</span></code>, it has to be freed
|
||||
using <code class="xref py py-func docutils literal notranslate"><span class="pre">PyMem_Del()</span></code>, not <code class="xref py py-func docutils literal notranslate"><span class="pre">free()</span></code>. A few modules included with Python
|
||||
fell afoul of this and had to be fixed; doubtless there are more third-party
|
||||
modules that will have the same problem.</p>
|
||||
<p>The object allocator was contributed by Vladimir Marangozov.</p>
|
||||
</li>
|
||||
<li><p>The speed of line-oriented file I/O has been improved because people often
|
||||
complain about its lack of speed, and because it’s often been used as a naïve
|
||||
benchmark. The <a class="reference internal" href="../library/readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">readline()</span></code></a> method of file objects has therefore been
|
||||
rewritten to be much faster. The exact amount of the speedup will vary from
|
||||
platform to platform depending on how slow the C library’s <code class="xref py py-func docutils literal notranslate"><span class="pre">getc()</span></code> was, but
|
||||
is around 66%, and potentially much faster on some particular operating systems.
|
||||
Tim Peters did much of the benchmarking and coding for this change, motivated by
|
||||
a discussion in comp.lang.python.</p>
|
||||
<p>A new module and method for file objects was also added, contributed by Jeff
|
||||
Epler. The new method, <code class="xref py py-meth docutils literal notranslate"><span class="pre">xreadlines()</span></code>, is similar to the existing
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">xrange()</span></code> built-in. <code class="xref py py-func docutils literal notranslate"><span class="pre">xreadlines()</span></code> returns an opaque sequence object
|
||||
that only supports being iterated over, reading a line on every iteration but
|
||||
not reading the entire file into memory as the existing <code class="xref py py-meth docutils literal notranslate"><span class="pre">readlines()</span></code> method
|
||||
does. You’d use it like this:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">xreadlines</span><span class="p">():</span>
|
||||
<span class="c1"># ... do something for each line ...</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>For a fuller discussion of the line I/O changes, see the python-dev summary for
|
||||
January 1–15, 2001 at <a class="reference external" href="https://mail.python.org/pipermail/python-dev/2001-January/">https://mail.python.org/pipermail/python-dev/2001-January/</a>.</p>
|
||||
</li>
|
||||
<li><p>A new method, <code class="xref py py-meth docutils literal notranslate"><span class="pre">popitem()</span></code>, was added to dictionaries to enable
|
||||
destructively iterating through the contents of a dictionary; this can be faster
|
||||
for large dictionaries because there’s no need to construct a list containing
|
||||
all the keys or values. <code class="docutils literal notranslate"><span class="pre">D.popitem()</span></code> removes a random <code class="docutils literal notranslate"><span class="pre">(key,</span> <span class="pre">value)</span></code> pair
|
||||
from the dictionary <code class="docutils literal notranslate"><span class="pre">D</span></code> and returns it as a 2-tuple. This was implemented
|
||||
mostly by Tim Peters and Guido van Rossum, after a suggestion and preliminary
|
||||
patch by Moshe Zadka.</p></li>
|
||||
<li><p>Modules can now control which names are imported when <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">module</span> <span class="pre">import</span> <span class="pre">*</span></code>
|
||||
is used, by defining an <code class="docutils literal notranslate"><span class="pre">__all__</span></code> attribute containing a list of names that
|
||||
will be imported. One common complaint is that if the module imports other
|
||||
modules such as <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> or <a class="reference internal" href="../library/string.html#module-string" title="string: Common string operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">string</span></code></a>, <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">module</span> <span class="pre">import</span> <span class="pre">*</span></code> will add
|
||||
them to the importing module’s namespace. To fix this, simply list the public
|
||||
names in <code class="docutils literal notranslate"><span class="pre">__all__</span></code>:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># List public names</span>
|
||||
<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'Database'</span><span class="p">,</span> <span class="s1">'open'</span><span class="p">]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>A stricter version of this patch was first suggested and implemented by Ben
|
||||
Wolfson, but after some python-dev discussion, a weaker final version was
|
||||
checked in.</p>
|
||||
</li>
|
||||
<li><p>Applying <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> to strings previously used octal escapes for
|
||||
non-printable characters; for example, a newline was <code class="docutils literal notranslate"><span class="pre">'\012'</span></code>. This was a
|
||||
vestigial trace of Python’s C ancestry, but today octal is of very little
|
||||
practical use. Ka-Ping Yee suggested using hex escapes instead of octal ones,
|
||||
and using the <code class="docutils literal notranslate"><span class="pre">\n</span></code>, <code class="docutils literal notranslate"><span class="pre">\t</span></code>, <code class="docutils literal notranslate"><span class="pre">\r</span></code> escapes for the appropriate characters,
|
||||
and implemented this new formatting.</p></li>
|
||||
<li><p>Syntax errors detected at compile-time can now raise exceptions containing the
|
||||
filename and line number of the error, a pleasant side effect of the compiler
|
||||
reorganization done by Jeremy Hylton.</p></li>
|
||||
<li><p>C extensions which import other modules have been changed to use
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">PyImport_ImportModule()</span></code>, which means that they will use any import hooks
|
||||
that have been installed. This is also encouraged for third-party extensions
|
||||
that need to import some other module from C code.</p></li>
|
||||
<li><p>The size of the Unicode character database was shrunk by another 340K thanks
|
||||
to Fredrik Lundh.</p></li>
|
||||
<li><p>Some new ports were contributed: MacOS X (by Steven Majewski), Cygwin (by
|
||||
Jason Tishler); RISCOS (by Dietmar Schwertberger); Unixware 7 (by Billy G.
|
||||
Allie).</p></li>
|
||||
</ul>
|
||||
<p>And there’s the usual list of minor bugfixes, minor memory leaks, docstring
|
||||
edits, and other tweaks, too lengthy to be worth itemizing; see the CVS logs for
|
||||
the full details if you want them.</p>
|
||||
</div>
|
||||
<div class="section" id="acknowledgements">
|
||||
<h2>Acknowledgements<a class="headerlink" href="#acknowledgements" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The author would like to thank the following people for offering suggestions on
|
||||
various drafts of this article: Graeme Cross, David Goodger, Jay Graves, Michael
|
||||
Hudson, Marc-André Lemburg, Fredrik Lundh, Neil Schemenauer, Thomas Wouters.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="../contents.html">Table of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">What’s New in Python 2.1</a><ul>
|
||||
<li><a class="reference internal" href="#introduction">Introduction</a></li>
|
||||
<li><a class="reference internal" href="#pep-227-nested-scopes">PEP 227: Nested Scopes</a></li>
|
||||
<li><a class="reference internal" href="#pep-236-future-directives">PEP 236: __future__ Directives</a></li>
|
||||
<li><a class="reference internal" href="#pep-207-rich-comparisons">PEP 207: Rich Comparisons</a></li>
|
||||
<li><a class="reference internal" href="#pep-230-warning-framework">PEP 230: Warning Framework</a></li>
|
||||
<li><a class="reference internal" href="#pep-229-new-build-system">PEP 229: New Build System</a></li>
|
||||
<li><a class="reference internal" href="#pep-205-weak-references">PEP 205: Weak References</a></li>
|
||||
<li><a class="reference internal" href="#pep-232-function-attributes">PEP 232: Function Attributes</a></li>
|
||||
<li><a class="reference internal" href="#pep-235-importing-modules-on-case-insensitive-platforms">PEP 235: Importing Modules on Case-Insensitive Platforms</a></li>
|
||||
<li><a class="reference internal" href="#pep-217-interactive-display-hook">PEP 217: Interactive Display Hook</a></li>
|
||||
<li><a class="reference internal" href="#pep-208-new-coercion-model">PEP 208: New Coercion Model</a></li>
|
||||
<li><a class="reference internal" href="#pep-241-metadata-in-python-packages">PEP 241: Metadata in Python Packages</a></li>
|
||||
<li><a class="reference internal" href="#new-and-improved-modules">New and Improved Modules</a></li>
|
||||
<li><a class="reference internal" href="#other-changes-and-fixes">Other Changes and Fixes</a></li>
|
||||
<li><a class="reference internal" href="#acknowledgements">Acknowledgements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="2.2.html"
|
||||
title="previous chapter">What’s New in Python 2.2</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="2.0.html"
|
||||
title="next chapter">What’s New in Python 2.0</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<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/3.7/Doc/whatsnew/2.1.rst"
|
||||
rel="nofollow">Show Source
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</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="2.0.html" title="What’s New in Python 2.0"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="2.2.html" title="What’s New in Python 2.2"
|
||||
>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>
|
||||
<span class="language_switcher_placeholder">en</span>
|
||||
<span class="version_switcher_placeholder">3.7.4</span>
|
||||
<a href="../index.html">Documentation </a> »
|
||||
</li>
|
||||
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> »</li>
|
||||
<li class="right">
|
||||
|
||||
|
||||
<div class="inline-search" style="display: none" role="search">
|
||||
<form class="inline-search" action="../search.html" method="get">
|
||||
<input placeholder="Quick search" type="text" name="q" />
|
||||
<input type="submit" value="Go" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||||
|
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer">
|
||||
© <a href="../copyright.html">Copyright</a> 2001-2019, 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 Jul 13, 2019.
|
||||
<a href="../bugs.html">Found a bug</a>?
|
||||
<br />
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
1303
python-3.7.4-docs-html/whatsnew/2.2.html
Normal file
1303
python-3.7.4-docs-html/whatsnew/2.2.html
Normal file
File diff suppressed because it is too large
Load Diff
2038
python-3.7.4-docs-html/whatsnew/2.3.html
Normal file
2038
python-3.7.4-docs-html/whatsnew/2.3.html
Normal file
File diff suppressed because it is too large
Load Diff
1570
python-3.7.4-docs-html/whatsnew/2.4.html
Normal file
1570
python-3.7.4-docs-html/whatsnew/2.4.html
Normal file
File diff suppressed because it is too large
Load Diff
2192
python-3.7.4-docs-html/whatsnew/2.5.html
Normal file
2192
python-3.7.4-docs-html/whatsnew/2.5.html
Normal file
File diff suppressed because it is too large
Load Diff
3171
python-3.7.4-docs-html/whatsnew/2.6.html
Normal file
3171
python-3.7.4-docs-html/whatsnew/2.6.html
Normal file
File diff suppressed because it is too large
Load Diff
2622
python-3.7.4-docs-html/whatsnew/2.7.html
Normal file
2622
python-3.7.4-docs-html/whatsnew/2.7.html
Normal file
File diff suppressed because it is too large
Load Diff
975
python-3.7.4-docs-html/whatsnew/3.0.html
Normal file
975
python-3.7.4-docs-html/whatsnew/3.0.html
Normal file
@@ -0,0 +1,975 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>What’s New In Python 3.0 — Python 3.7.4 documentation</title>
|
||||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></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/language_data.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
||||
|
||||
<link rel="search" type="application/opensearchdescription+xml"
|
||||
title="Search within Python 3.7.4 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="What’s New in Python 2.7" href="2.7.html" />
|
||||
<link rel="prev" title="What’s New In Python 3.1" href="3.1.html" />
|
||||
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
|
||||
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.0.html" />
|
||||
|
||||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||||
<script type="text/javascript" src="../_static/switchers.js"></script>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
@media only screen {
|
||||
table.full-width-table {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
</head><body>
|
||||
|
||||
<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="2.7.html" title="What’s New in Python 2.7"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="3.1.html" title="What’s New In Python 3.1"
|
||||
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>
|
||||
<span class="language_switcher_placeholder">en</span>
|
||||
<span class="version_switcher_placeholder">3.7.4</span>
|
||||
<a href="../index.html">Documentation </a> »
|
||||
</li>
|
||||
|
||||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> »</li>
|
||||
<li class="right">
|
||||
|
||||
|
||||
<div class="inline-search" style="display: none" role="search">
|
||||
<form class="inline-search" action="../search.html" method="get">
|
||||
<input placeholder="Quick search" type="text" name="q" />
|
||||
<input type="submit" value="Go" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||||
|
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="what-s-new-in-python-3-0">
|
||||
<h1>What’s New In Python 3.0<a class="headerlink" href="#what-s-new-in-python-3-0" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Author</dt>
|
||||
<dd class="field-odd"><p>Guido van Rossum</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<p>This article explains the new features in Python 3.0, compared to 2.6.
|
||||
Python 3.0, also known as “Python 3000” or “Py3K”, is the first ever
|
||||
<em>intentionally backwards incompatible</em> Python release. There are more
|
||||
changes than in a typical release, and more that are important for all
|
||||
Python users. Nevertheless, after digesting the changes, you’ll find
|
||||
that Python really hasn’t changed all that much – by and large, we’re
|
||||
mostly fixing well-known annoyances and warts, and removing a lot of
|
||||
old cruft.</p>
|
||||
<p>This article doesn’t attempt to provide a complete specification of
|
||||
all new features, but instead tries to give a convenient overview.
|
||||
For full details, you should refer to the documentation for Python
|
||||
3.0, and/or the many PEPs referenced in the text. If you want to
|
||||
understand the complete implementation and design rationale for a
|
||||
particular feature, PEPs usually have more details than the regular
|
||||
documentation; but note that PEPs usually are not kept up-to-date once
|
||||
a feature has been fully implemented.</p>
|
||||
<p>Due to time constraints this document is not as complete as it should
|
||||
have been. As always for a new release, the <code class="docutils literal notranslate"><span class="pre">Misc/NEWS</span></code> file in the
|
||||
source distribution contains a wealth of detailed information about
|
||||
every small thing that was changed.</p>
|
||||
<div class="section" id="common-stumbling-blocks">
|
||||
<h2>Common Stumbling Blocks<a class="headerlink" href="#common-stumbling-blocks" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This section lists those few changes that are most likely to trip you
|
||||
up if you’re used to Python 2.5.</p>
|
||||
<div class="section" id="print-is-a-function">
|
||||
<h3>Print Is A Function<a class="headerlink" href="#print-is-a-function" title="Permalink to this headline">¶</a></h3>
|
||||
<p>The <code class="docutils literal notranslate"><span class="pre">print</span></code> statement has been replaced with a <a class="reference internal" href="../library/functions.html#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a>
|
||||
function, with keyword arguments to replace most of the special syntax
|
||||
of the old <code class="docutils literal notranslate"><span class="pre">print</span></code> statement (<span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3105"><strong>PEP 3105</strong></a>). Examples:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Old</span><span class="p">:</span> <span class="nb">print</span> <span class="s2">"The answer is"</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="mi">2</span>
|
||||
<span class="n">New</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"The answer is"</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="mi">2</span><span class="p">)</span>
|
||||
|
||||
<span class="n">Old</span><span class="p">:</span> <span class="nb">print</span> <span class="n">x</span><span class="p">,</span> <span class="c1"># Trailing comma suppresses newline</span>
|
||||
<span class="n">New</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">" "</span><span class="p">)</span> <span class="c1"># Appends a space instead of a newline</span>
|
||||
|
||||
<span class="n">Old</span><span class="p">:</span> <span class="nb">print</span> <span class="c1"># Prints a newline</span>
|
||||
<span class="n">New</span><span class="p">:</span> <span class="nb">print</span><span class="p">()</span> <span class="c1"># You must call the function!</span>
|
||||
|
||||
<span class="n">Old</span><span class="p">:</span> <span class="nb">print</span> <span class="o">>></span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="p">,</span> <span class="s2">"fatal error"</span>
|
||||
<span class="n">New</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"fatal error"</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="p">)</span>
|
||||
|
||||
<span class="n">Old</span><span class="p">:</span> <span class="nb">print</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span> <span class="c1"># prints repr((x, y))</span>
|
||||
<span class="n">New</span><span class="p">:</span> <span class="nb">print</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span> <span class="c1"># Not the same as print(x, y)!</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>You can also customize the separator between items, e.g.:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">"There are <"</span><span class="p">,</span> <span class="mi">2</span><span class="o">**</span><span class="mi">32</span><span class="p">,</span> <span class="s2">"> possibilities!"</span><span class="p">,</span> <span class="n">sep</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>which produces:</p>
|
||||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>There are <4294967296> possibilities!
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Note:</p>
|
||||
<ul class="simple">
|
||||
<li><p>The <a class="reference internal" href="../library/functions.html#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a> function doesn’t support the “softspace” feature of
|
||||
the old <code class="docutils literal notranslate"><span class="pre">print</span></code> statement. For example, in Python 2.x,
|
||||
<code class="docutils literal notranslate"><span class="pre">print</span> <span class="pre">"A\n",</span> <span class="pre">"B"</span></code> would write <code class="docutils literal notranslate"><span class="pre">"A\nB\n"</span></code>; but in Python 3.0,
|
||||
<code class="docutils literal notranslate"><span class="pre">print("A\n",</span> <span class="pre">"B")</span></code> writes <code class="docutils literal notranslate"><span class="pre">"A\n</span> <span class="pre">B\n"</span></code>.</p></li>
|
||||
<li><p>Initially, you’ll be finding yourself typing the old <code class="docutils literal notranslate"><span class="pre">print</span> <span class="pre">x</span></code>
|
||||
a lot in interactive mode. Time to retrain your fingers to type
|
||||
<code class="docutils literal notranslate"><span class="pre">print(x)</span></code> instead!</p></li>
|
||||
<li><p>When using the <code class="docutils literal notranslate"><span class="pre">2to3</span></code> source-to-source conversion tool, all
|
||||
<code class="docutils literal notranslate"><span class="pre">print</span></code> statements are automatically converted to
|
||||
<a class="reference internal" href="../library/functions.html#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a> function calls, so this is mostly a non-issue for
|
||||
larger projects.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="views-and-iterators-instead-of-lists">
|
||||
<h3>Views And Iterators Instead Of Lists<a class="headerlink" href="#views-and-iterators-instead-of-lists" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Some well-known APIs no longer return lists:</p>
|
||||
<ul>
|
||||
<li><p><a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> methods <a class="reference internal" href="../library/stdtypes.html#dict.keys" title="dict.keys"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.keys()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#dict.items" title="dict.items"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.items()</span></code></a> and
|
||||
<a class="reference internal" href="../library/stdtypes.html#dict.values" title="dict.values"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.values()</span></code></a> return “views” instead of lists. For example,
|
||||
this no longer works: <code class="docutils literal notranslate"><span class="pre">k</span> <span class="pre">=</span> <span class="pre">d.keys();</span> <span class="pre">k.sort()</span></code>. Use <code class="docutils literal notranslate"><span class="pre">k</span> <span class="pre">=</span>
|
||||
<span class="pre">sorted(d)</span></code> instead (this works in Python 2.5 too and is just
|
||||
as efficient).</p></li>
|
||||
<li><p>Also, the <code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.iterkeys()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.iteritems()</span></code> and
|
||||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.itervalues()</span></code> methods are no longer supported.</p></li>
|
||||
<li><p><a class="reference internal" href="../library/functions.html#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a> and <a class="reference internal" href="../library/functions.html#filter" title="filter"><code class="xref py py-func docutils literal notranslate"><span class="pre">filter()</span></code></a> return iterators. If you really need
|
||||
a list and the input sequences are all of equal length, a quick
|
||||
fix is to wrap <a class="reference internal" href="../library/functions.html#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a> in <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-func docutils literal notranslate"><span class="pre">list()</span></code></a>, e.g. <code class="docutils literal notranslate"><span class="pre">list(map(...))</span></code>,
|
||||
but a better fix is
|
||||
often to use a list comprehension (especially when the original code
|
||||
uses <a class="reference internal" href="../reference/expressions.html#lambda"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">lambda</span></code></a>), or rewriting the code so it doesn’t need a
|
||||
list at all. Particularly tricky is <a class="reference internal" href="../library/functions.html#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a> invoked for the
|
||||
side effects of the function; the correct transformation is to use a
|
||||
regular <a class="reference internal" href="../reference/compound_stmts.html#for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code></a> loop (since creating a list would just be
|
||||
wasteful).</p>
|
||||
<p>If the input sequences are not of equal length, <a class="reference internal" href="../library/functions.html#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a> will
|
||||
stop at the termination of the shortest of the sequences. For full
|
||||
compatibility with <a class="reference internal" href="../library/functions.html#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a> from Python 2.x, also wrap the sequences in
|
||||
<a class="reference internal" href="../library/itertools.html#itertools.zip_longest" title="itertools.zip_longest"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.zip_longest()</span></code></a>, e.g. <code class="docutils literal notranslate"><span class="pre">map(func,</span> <span class="pre">*sequences)</span></code> becomes
|
||||
<code class="docutils literal notranslate"><span class="pre">list(map(func,</span> <span class="pre">itertools.zip_longest(*sequences)))</span></code>.</p>
|
||||
</li>
|
||||
<li><p><a class="reference internal" href="../library/stdtypes.html#range" title="range"><code class="xref py py-func docutils literal notranslate"><span class="pre">range()</span></code></a> now behaves like <code class="xref py py-func docutils literal notranslate"><span class="pre">xrange()</span></code> used to behave, except
|
||||
it works with values of arbitrary size. The latter no longer
|
||||
exists.</p></li>
|
||||
<li><p><a class="reference internal" href="../library/functions.html#zip" title="zip"><code class="xref py py-func docutils literal notranslate"><span class="pre">zip()</span></code></a> now returns an iterator.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="ordering-comparisons">
|
||||
<h3>Ordering Comparisons<a class="headerlink" href="#ordering-comparisons" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Python 3.0 has simplified the rules for ordering comparisons:</p>
|
||||
<ul class="simple">
|
||||
<li><p>The ordering comparison operators (<code class="docutils literal notranslate"><span class="pre"><</span></code>, <code class="docutils literal notranslate"><span class="pre"><=</span></code>, <code class="docutils literal notranslate"><span class="pre">>=</span></code>, <code class="docutils literal notranslate"><span class="pre">></span></code>)
|
||||
raise a TypeError exception when the operands don’t have a
|
||||
meaningful natural ordering. Thus, expressions like <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre"><</span> <span class="pre">''</span></code>, <code class="docutils literal notranslate"><span class="pre">0</span>
|
||||
<span class="pre">></span> <span class="pre">None</span></code> or <code class="docutils literal notranslate"><span class="pre">len</span> <span class="pre"><=</span> <span class="pre">len</span></code> are no longer valid, and e.g. <code class="docutils literal notranslate"><span class="pre">None</span> <span class="pre"><</span>
|
||||
<span class="pre">None</span></code> raises <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> instead of returning
|
||||
<code class="docutils literal notranslate"><span class="pre">False</span></code>. A corollary is that sorting a heterogeneous list
|
||||
no longer makes sense – all the elements must be comparable to each
|
||||
other. Note that this does not apply to the <code class="docutils literal notranslate"><span class="pre">==</span></code> and <code class="docutils literal notranslate"><span class="pre">!=</span></code>
|
||||
operators: objects of different incomparable types always compare
|
||||
unequal to each other.</p></li>
|
||||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">builtin.sorted()</span></code> and <a class="reference internal" href="../library/stdtypes.html#list.sort" title="list.sort"><code class="xref py py-meth docutils literal notranslate"><span class="pre">list.sort()</span></code></a> no longer accept the
|
||||
<em>cmp</em> argument providing a comparison function. Use the <em>key</em>
|
||||
argument instead. N.B. the <em>key</em> and <em>reverse</em> arguments are now
|
||||
“keyword-only”.</p></li>
|
||||
<li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">cmp()</span></code> function should be treated as gone, and the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__cmp__()</span></code>
|
||||
special method is no longer supported. Use <a class="reference internal" href="../reference/datamodel.html#object.__lt__" title="object.__lt__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__lt__()</span></code></a> for sorting,
|
||||
<a class="reference internal" href="../reference/datamodel.html#object.__eq__" title="object.__eq__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__eq__()</span></code></a> with <a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__hash__()</span></code></a>, and other rich comparisons as needed.
|
||||
(If you really need the <code class="xref py py-func docutils literal notranslate"><span class="pre">cmp()</span></code> functionality, you could use the
|
||||
expression <code class="docutils literal notranslate"><span class="pre">(a</span> <span class="pre">></span> <span class="pre">b)</span> <span class="pre">-</span> <span class="pre">(a</span> <span class="pre"><</span> <span class="pre">b)</span></code> as the equivalent for <code class="docutils literal notranslate"><span class="pre">cmp(a,</span> <span class="pre">b)</span></code>.)</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="integers">
|
||||
<h3>Integers<a class="headerlink" href="#integers" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p><span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0237"><strong>PEP 237</strong></a>: Essentially, <code class="xref py py-class docutils literal notranslate"><span class="pre">long</span></code> renamed to <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>.
|
||||
That is, there is only one built-in integral type, named
|
||||
<a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>; but it behaves mostly like the old <code class="xref py py-class docutils literal notranslate"><span class="pre">long</span></code> type.</p></li>
|
||||
<li><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0238"><strong>PEP 238</strong></a>: An expression like <code class="docutils literal notranslate"><span class="pre">1/2</span></code> returns a float. Use
|
||||
<code class="docutils literal notranslate"><span class="pre">1//2</span></code> to get the truncating behavior. (The latter syntax has
|
||||
existed for years, at least since Python 2.2.)</p></li>
|
||||
<li><p>The <code class="xref py py-data docutils literal notranslate"><span class="pre">sys.maxint</span></code> constant was removed, since there is no
|
||||
longer a limit to the value of integers. However, <a class="reference internal" href="../library/sys.html#sys.maxsize" title="sys.maxsize"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.maxsize</span></code></a>
|
||||
can be used as an integer larger than any practical list or string
|
||||
index. It conforms to the implementation’s “natural” integer size
|
||||
and is typically the same as <code class="xref py py-data docutils literal notranslate"><span class="pre">sys.maxint</span></code> in previous releases
|
||||
on the same platform (assuming the same build options).</p></li>
|
||||
<li><p>The <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> of a long integer doesn’t include the trailing <code class="docutils literal notranslate"><span class="pre">L</span></code>
|
||||
anymore, so code that unconditionally strips that character will
|
||||
chop off the last digit instead. (Use <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> instead.)</p></li>
|
||||
<li><p>Octal literals are no longer of the form <code class="docutils literal notranslate"><span class="pre">0720</span></code>; use <code class="docutils literal notranslate"><span class="pre">0o720</span></code>
|
||||
instead.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="text-vs-data-instead-of-unicode-vs-8-bit">
|
||||
<h3>Text Vs. Data Instead Of Unicode Vs. 8-bit<a class="headerlink" href="#text-vs-data-instead-of-unicode-vs-8-bit" title="Permalink to this headline">¶</a></h3>
|
||||
<p>Everything you thought you knew about binary data and Unicode has
|
||||
changed.</p>
|
||||
<ul class="simple">
|
||||
<li><p>Python 3.0 uses the concepts of <em>text</em> and (binary) <em>data</em> instead
|
||||
of Unicode strings and 8-bit strings. All text is Unicode; however
|
||||
<em>encoded</em> Unicode is represented as binary data. The type used to
|
||||
hold text is <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, the type used to hold data is
|
||||
<a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>. The biggest difference with the 2.x situation is
|
||||
that any attempt to mix text and data in Python 3.0 raises
|
||||
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>, whereas if you were to mix Unicode and 8-bit
|
||||
strings in Python 2.x, it would work if the 8-bit string happened to
|
||||
contain only 7-bit (ASCII) bytes, but you would get
|
||||
<a class="reference internal" href="../library/exceptions.html#UnicodeDecodeError" title="UnicodeDecodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code></a> if it contained non-ASCII values. This
|
||||
value-specific behavior has caused numerous sad faces over the
|
||||
years.</p></li>
|
||||
<li><p>As a consequence of this change in philosophy, pretty much all code
|
||||
that uses Unicode, encodings or binary data most likely has to
|
||||
change. The change is for the better, as in the 2.x world there
|
||||
were numerous bugs having to do with mixing encoded and unencoded
|
||||
text. To be prepared in Python 2.x, start using <code class="xref py py-class docutils literal notranslate"><span class="pre">unicode</span></code>
|
||||
for all unencoded text, and <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> for binary or encoded data
|
||||
only. Then the <code class="docutils literal notranslate"><span class="pre">2to3</span></code> tool will do most of the work for you.</p></li>
|
||||
<li><p>You can no longer use <code class="docutils literal notranslate"><span class="pre">u"..."</span></code> literals for Unicode text.
|
||||
However, you must use <code class="docutils literal notranslate"><span class="pre">b"..."</span></code> literals for binary data.</p></li>
|
||||
<li><p>As the <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> types cannot be mixed, you
|
||||
must always explicitly convert between them. Use <a class="reference internal" href="../library/stdtypes.html#str.encode" title="str.encode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.encode()</span></code></a>
|
||||
to go from <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> to <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>, and <a class="reference internal" href="../library/stdtypes.html#bytes.decode" title="bytes.decode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytes.decode()</span></code></a>
|
||||
to go from <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> to <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>. You can also use
|
||||
<code class="docutils literal notranslate"><span class="pre">bytes(s,</span> <span class="pre">encoding=...)</span></code> and <code class="docutils literal notranslate"><span class="pre">str(b,</span> <span class="pre">encoding=...)</span></code>,
|
||||
respectively.</p></li>
|
||||
<li><p>Like <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, the <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> type is immutable. There is a
|
||||
separate <em>mutable</em> type to hold buffered binary data,
|
||||
<a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>. Nearly all APIs that accept <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> also
|
||||
accept <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>. The mutable API is based on
|
||||
<code class="xref py py-class docutils literal notranslate"><span class="pre">collections.MutableSequence</span></code>.</p></li>
|
||||
<li><p>All backslashes in raw string literals are interpreted literally.
|
||||
This means that <code class="docutils literal notranslate"><span class="pre">'\U'</span></code> and <code class="docutils literal notranslate"><span class="pre">'\u'</span></code> escapes in raw strings are not
|
||||
treated specially. For example, <code class="docutils literal notranslate"><span class="pre">r'\u20ac'</span></code> is a string of 6
|
||||
characters in Python 3.0, whereas in 2.6, <code class="docutils literal notranslate"><span class="pre">ur'\u20ac'</span></code> was the
|
||||
single “euro” character. (Of course, this change only affects raw
|
||||
string literals; the euro character is <code class="docutils literal notranslate"><span class="pre">'\u20ac'</span></code> in Python 3.0.)</p></li>
|
||||
<li><p>The built-in <code class="xref py py-class docutils literal notranslate"><span class="pre">basestring</span></code> abstract type was removed. Use
|
||||
<a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> instead. The <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> types
|
||||
don’t have functionality enough in common to warrant a shared base
|
||||
class. The <code class="docutils literal notranslate"><span class="pre">2to3</span></code> tool (see below) replaces every occurrence of
|
||||
<code class="xref py py-class docutils literal notranslate"><span class="pre">basestring</span></code> with <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>.</p></li>
|
||||
<li><p>Files opened as text files (still the default mode for <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>)
|
||||
always use an encoding to map between strings (in memory) and bytes
|
||||
(on disk). Binary files (opened with a <code class="docutils literal notranslate"><span class="pre">b</span></code> in the mode argument)
|
||||
always use bytes in memory. This means that if a file is opened
|
||||
using an incorrect mode or encoding, I/O will likely fail loudly,
|
||||
instead of silently producing incorrect data. It also means that
|
||||
even Unix users will have to specify the correct mode (text or
|
||||
binary) when opening a file. There is a platform-dependent default
|
||||
encoding, which on Unixy platforms can be set with the <code class="docutils literal notranslate"><span class="pre">LANG</span></code>
|
||||
environment variable (and sometimes also with some other
|
||||
platform-specific locale-related environment variables). In many
|
||||
cases, but not all, the system default is UTF-8; you should never
|
||||
count on this default. Any application reading or writing more than
|
||||
pure ASCII text should probably have a way to override the encoding.
|
||||
There is no longer any need for using the encoding-aware streams
|
||||
in the <a class="reference internal" href="../library/codecs.html#module-codecs" title="codecs: Encode and decode data and streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">codecs</span></code></a> module.</p></li>
|
||||
<li><p>The initial values of <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>, <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> and
|
||||
<a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> are now unicode-only text files (i.e., they are
|
||||
instances of <a class="reference internal" href="../library/io.html#io.TextIOBase" title="io.TextIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOBase</span></code></a>). To read and write bytes data
|
||||
with these streams, you need to use their <a class="reference internal" href="../library/io.html#io.TextIOBase.buffer" title="io.TextIOBase.buffer"><code class="xref py py-data docutils literal notranslate"><span class="pre">io.TextIOBase.buffer</span></code></a>
|
||||
attribute.</p></li>
|
||||
<li><p>Filenames are passed to and returned from APIs as (Unicode) strings.
|
||||
This can present platform-specific problems because on some
|
||||
platforms filenames are arbitrary byte strings. (On the other hand,
|
||||
on Windows filenames are natively stored as Unicode.) As a
|
||||
work-around, most APIs (e.g. <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> and many functions in the
|
||||
<a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module) that take filenames accept <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> objects
|
||||
as well as strings, and a few APIs have a way to ask for a
|
||||
<a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> return value. Thus, <a class="reference internal" href="../library/os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdir()</span></code></a> returns a
|
||||
list of <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> instances if the argument is a <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>
|
||||
instance, and <a class="reference internal" href="../library/os.html#os.getcwdb" title="os.getcwdb"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getcwdb()</span></code></a> returns the current working
|
||||
directory as a <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> instance. Note that when
|
||||
<a class="reference internal" href="../library/os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdir()</span></code></a> returns a list of strings, filenames that
|
||||
cannot be decoded properly are omitted rather than raising
|
||||
<a class="reference internal" href="../library/exceptions.html#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a>.</p></li>
|
||||
<li><p>Some system APIs like <a class="reference internal" href="../library/os.html#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> can
|
||||
also present problems when the bytes made available by the system is
|
||||
not interpretable using the default encoding. Setting the <code class="docutils literal notranslate"><span class="pre">LANG</span></code>
|
||||
variable and rerunning the program is probably the best approach.</p></li>
|
||||
<li><p><span class="target" id="index-3"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3138"><strong>PEP 3138</strong></a>: The <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> of a string no longer escapes
|
||||
non-ASCII characters. It still escapes control characters and code
|
||||
points with non-printable status in the Unicode standard, however.</p></li>
|
||||
<li><p><span class="target" id="index-4"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3120"><strong>PEP 3120</strong></a>: The default source encoding is now UTF-8.</p></li>
|
||||
<li><p><span class="target" id="index-5"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3131"><strong>PEP 3131</strong></a>: Non-ASCII letters are now allowed in identifiers.
|
||||
(However, the standard library remains ASCII-only with the exception
|
||||
of contributor names in comments.)</p></li>
|
||||
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">StringIO</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">cStringIO</span></code> modules are gone. Instead,
|
||||
import the <a class="reference internal" href="../library/io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a> module and use <a class="reference internal" href="../library/io.html#io.StringIO" title="io.StringIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.StringIO</span></code></a> or
|
||||
<a class="reference internal" href="../library/io.html#io.BytesIO" title="io.BytesIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BytesIO</span></code></a> for text and data respectively.</p></li>
|
||||
<li><p>See also the <a class="reference internal" href="../howto/unicode.html#unicode-howto"><span class="std std-ref">Unicode HOWTO</span></a>, which was updated for Python 3.0.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="overview-of-syntax-changes">
|
||||
<h2>Overview Of Syntax Changes<a class="headerlink" href="#overview-of-syntax-changes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This section gives a brief overview of every <em>syntactic</em> change in
|
||||
Python 3.0.</p>
|
||||
<div class="section" id="new-syntax">
|
||||
<h3>New Syntax<a class="headerlink" href="#new-syntax" title="Permalink to this headline">¶</a></h3>
|
||||
<ul>
|
||||
<li><p><span class="target" id="index-6"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3107"><strong>PEP 3107</strong></a>: Function argument and return value annotations. This
|
||||
provides a standardized way of annotating a function’s parameters
|
||||
and return value. There are no semantics attached to such
|
||||
annotations except that they can be introspected at runtime using
|
||||
the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__annotations__</span></code> attribute. The intent is to encourage
|
||||
experimentation through metaclasses, decorators or frameworks.</p></li>
|
||||
<li><p><span class="target" id="index-7"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3102"><strong>PEP 3102</strong></a>: Keyword-only arguments. Named parameters occurring
|
||||
after <code class="docutils literal notranslate"><span class="pre">*args</span></code> in the parameter list <em>must</em> be specified using
|
||||
keyword syntax in the call. You can also use a bare <code class="docutils literal notranslate"><span class="pre">*</span></code> in the
|
||||
parameter list to indicate that you don’t accept a variable-length
|
||||
argument list, but you do have keyword-only arguments.</p></li>
|
||||
<li><p>Keyword arguments are allowed after the list of base classes in a
|
||||
class definition. This is used by the new convention for specifying
|
||||
a metaclass (see next section), but can be used for other purposes
|
||||
as well, as long as the metaclass supports it.</p></li>
|
||||
<li><p><span class="target" id="index-8"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3104"><strong>PEP 3104</strong></a>: <a class="reference internal" href="../reference/simple_stmts.html#nonlocal"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">nonlocal</span></code></a> statement. Using <code class="docutils literal notranslate"><span class="pre">nonlocal</span> <span class="pre">x</span></code>
|
||||
you can now assign directly to a variable in an outer (but
|
||||
non-global) scope. <code class="xref std std-keyword docutils literal notranslate"><span class="pre">nonlocal</span></code> is a new reserved word.</p></li>
|
||||
<li><p><span class="target" id="index-9"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3132"><strong>PEP 3132</strong></a>: Extended Iterable Unpacking. You can now write things
|
||||
like <code class="docutils literal notranslate"><span class="pre">a,</span> <span class="pre">b,</span> <span class="pre">*rest</span> <span class="pre">=</span> <span class="pre">some_sequence</span></code>. And even <code class="docutils literal notranslate"><span class="pre">*rest,</span> <span class="pre">a</span> <span class="pre">=</span>
|
||||
<span class="pre">stuff</span></code>. The <code class="docutils literal notranslate"><span class="pre">rest</span></code> object is always a (possibly empty) list; the
|
||||
right-hand side may be any iterable. Example:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="n">rest</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>This sets <em>a</em> to <code class="docutils literal notranslate"><span class="pre">0</span></code>, <em>b</em> to <code class="docutils literal notranslate"><span class="pre">4</span></code>, and <em>rest</em> to <code class="docutils literal notranslate"><span class="pre">[1,</span> <span class="pre">2,</span> <span class="pre">3]</span></code>.</p>
|
||||
</li>
|
||||
<li><p>Dictionary comprehensions: <code class="docutils literal notranslate"><span class="pre">{k:</span> <span class="pre">v</span> <span class="pre">for</span> <span class="pre">k,</span> <span class="pre">v</span> <span class="pre">in</span> <span class="pre">stuff}</span></code> means the
|
||||
same thing as <code class="docutils literal notranslate"><span class="pre">dict(stuff)</span></code> but is more flexible. (This is
|
||||
<span class="target" id="index-10"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0274"><strong>PEP 274</strong></a> vindicated. :-)</p></li>
|
||||
<li><p>Set literals, e.g. <code class="docutils literal notranslate"><span class="pre">{1,</span> <span class="pre">2}</span></code>. Note that <code class="docutils literal notranslate"><span class="pre">{}</span></code> is an empty
|
||||
dictionary; use <code class="docutils literal notranslate"><span class="pre">set()</span></code> for an empty set. Set comprehensions are
|
||||
also supported; e.g., <code class="docutils literal notranslate"><span class="pre">{x</span> <span class="pre">for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">stuff}</span></code> means the same thing as
|
||||
<code class="docutils literal notranslate"><span class="pre">set(stuff)</span></code> but is more flexible.</p></li>
|
||||
<li><p>New octal literals, e.g. <code class="docutils literal notranslate"><span class="pre">0o720</span></code> (already in 2.6). The old octal
|
||||
literals (<code class="docutils literal notranslate"><span class="pre">0720</span></code>) are gone.</p></li>
|
||||
<li><p>New binary literals, e.g. <code class="docutils literal notranslate"><span class="pre">0b1010</span></code> (already in 2.6), and
|
||||
there is a new corresponding built-in function, <a class="reference internal" href="../library/functions.html#bin" title="bin"><code class="xref py py-func docutils literal notranslate"><span class="pre">bin()</span></code></a>.</p></li>
|
||||
<li><p>Bytes literals are introduced with a leading <code class="docutils literal notranslate"><span class="pre">b</span></code> or <code class="docutils literal notranslate"><span class="pre">B</span></code>, and
|
||||
there is a new corresponding built-in function, <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">bytes()</span></code></a>.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="changed-syntax">
|
||||
<h3>Changed Syntax<a class="headerlink" href="#changed-syntax" title="Permalink to this headline">¶</a></h3>
|
||||
<ul>
|
||||
<li><p><span class="target" id="index-11"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3109"><strong>PEP 3109</strong></a> and <span class="target" id="index-12"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3134"><strong>PEP 3134</strong></a>: new <a class="reference internal" href="../reference/simple_stmts.html#raise"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">raise</span></code></a> statement syntax:
|
||||
<code class="samp docutils literal notranslate"><span class="pre">raise</span> <span class="pre">[</span><em><span class="pre">expr</span></em> <span class="pre">[from</span> <em><span class="pre">expr</span></em><span class="pre">]]</span></code>. See below.</p></li>
|
||||
<li><p><code class="xref std std-keyword docutils literal notranslate"><span class="pre">as</span></code> and <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> are now reserved words. (Since
|
||||
2.6, actually.)</p></li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="docutils literal notranslate"><span class="pre">False</span></code>, and <code class="docutils literal notranslate"><span class="pre">None</span></code> are reserved words. (2.6 partially enforced
|
||||
the restrictions on <code class="docutils literal notranslate"><span class="pre">None</span></code> already.)</p></li>
|
||||
<li><p>Change from <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> <em>exc</em>, <em>var</em> to
|
||||
<code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code> <em>exc</em> <code class="xref std std-keyword docutils literal notranslate"><span class="pre">as</span></code> <em>var</em>. See <span class="target" id="index-13"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3110"><strong>PEP 3110</strong></a>.</p></li>
|
||||
<li><p><span class="target" id="index-14"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3115"><strong>PEP 3115</strong></a>: New Metaclass Syntax. Instead of:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
|
||||
<span class="n">__metaclass__</span> <span class="o">=</span> <span class="n">M</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>you must now use:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">C</span><span class="p">(</span><span class="n">metaclass</span><span class="o">=</span><span class="n">M</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The module-global <code class="xref py py-data docutils literal notranslate"><span class="pre">__metaclass__</span></code> variable is no longer
|
||||
supported. (It was a crutch to make it easier to default to
|
||||
new-style classes without deriving every class from
|
||||
<a class="reference internal" href="../library/functions.html#object" title="object"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a>.)</p>
|
||||
</li>
|
||||
<li><p>List comprehensions no longer support the syntactic form
|
||||
<code class="samp docutils literal notranslate"><span class="pre">[...</span> <span class="pre">for</span> <em><span class="pre">var</span></em> <span class="pre">in</span> <em><span class="pre">item1</span></em><span class="pre">,</span> <em><span class="pre">item2</span></em><span class="pre">,</span> <span class="pre">...]</span></code>. Use
|
||||
<code class="samp docutils literal notranslate"><span class="pre">[...</span> <span class="pre">for</span> <em><span class="pre">var</span></em> <span class="pre">in</span> <span class="pre">(</span><em><span class="pre">item1</span></em><span class="pre">,</span> <em><span class="pre">item2</span></em><span class="pre">,</span> <span class="pre">...)]</span></code> instead.
|
||||
Also note that list comprehensions have different semantics: they
|
||||
are closer to syntactic sugar for a generator expression inside a
|
||||
<a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-func docutils literal notranslate"><span class="pre">list()</span></code></a> constructor, and in particular the loop control
|
||||
variables are no longer leaked into the surrounding scope.</p></li>
|
||||
<li><p>The <em>ellipsis</em> (<code class="docutils literal notranslate"><span class="pre">...</span></code>) can be used as an atomic expression
|
||||
anywhere. (Previously it was only allowed in slices.) Also, it
|
||||
<em>must</em> now be spelled as <code class="docutils literal notranslate"><span class="pre">...</span></code>. (Previously it could also be
|
||||
spelled as <code class="docutils literal notranslate"><span class="pre">.</span> <span class="pre">.</span> <span class="pre">.</span></code>, by a mere accident of the grammar.)</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="removed-syntax">
|
||||
<h3>Removed Syntax<a class="headerlink" href="#removed-syntax" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p><span class="target" id="index-15"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3113"><strong>PEP 3113</strong></a>: Tuple parameter unpacking removed. You can no longer
|
||||
write <code class="docutils literal notranslate"><span class="pre">def</span> <span class="pre">foo(a,</span> <span class="pre">(b,</span> <span class="pre">c)):</span> <span class="pre">...</span></code>.
|
||||
Use <code class="docutils literal notranslate"><span class="pre">def</span> <span class="pre">foo(a,</span> <span class="pre">b_c):</span> <span class="pre">b,</span> <span class="pre">c</span> <span class="pre">=</span> <span class="pre">b_c</span></code> instead.</p></li>
|
||||
<li><p>Removed backticks (use <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> instead).</p></li>
|
||||
<li><p>Removed <code class="docutils literal notranslate"><span class="pre"><></span></code> (use <code class="docutils literal notranslate"><span class="pre">!=</span></code> instead).</p></li>
|
||||
<li><p>Removed keyword: <a class="reference internal" href="../library/functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> is no longer a keyword; it remains as
|
||||
a function. (Fortunately the function syntax was also accepted in
|
||||
2.x.) Also note that <a class="reference internal" href="../library/functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> no longer takes a stream argument;
|
||||
instead of <code class="docutils literal notranslate"><span class="pre">exec(f)</span></code> you can use <code class="docutils literal notranslate"><span class="pre">exec(f.read())</span></code>.</p></li>
|
||||
<li><p>Integer literals no longer support a trailing <code class="docutils literal notranslate"><span class="pre">l</span></code> or <code class="docutils literal notranslate"><span class="pre">L</span></code>.</p></li>
|
||||
<li><p>String literals no longer support a leading <code class="docutils literal notranslate"><span class="pre">u</span></code> or <code class="docutils literal notranslate"><span class="pre">U</span></code>.</p></li>
|
||||
<li><p>The <a class="reference internal" href="../reference/simple_stmts.html#from"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">from</span></code></a> <em>module</em> <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> <code class="docutils literal notranslate"><span class="pre">*</span></code> syntax is only
|
||||
allowed at the module level, no longer inside functions.</p></li>
|
||||
<li><p>The only acceptable syntax for relative imports is <code class="samp docutils literal notranslate"><span class="pre">from</span> <span class="pre">.[</span><em><span class="pre">module</span></em><span class="pre">]</span>
|
||||
<span class="pre">import</span> <em><span class="pre">name</span></em></code>. All <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> forms not starting with <code class="docutils literal notranslate"><span class="pre">.</span></code> are
|
||||
interpreted as absolute imports. (<span class="target" id="index-16"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0328"><strong>PEP 328</strong></a>)</p></li>
|
||||
<li><p>Classic classes are gone.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="changes-already-present-in-python-2-6">
|
||||
<h2>Changes Already Present In Python 2.6<a class="headerlink" href="#changes-already-present-in-python-2-6" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Since many users presumably make the jump straight from Python 2.5 to
|
||||
Python 3.0, this section reminds the reader of new features that were
|
||||
originally designed for Python 3.0 but that were back-ported to Python
|
||||
2.6. The corresponding sections in <a class="reference internal" href="2.6.html#whats-new-in-2-6"><span class="std std-ref">What’s New in Python 2.6</span></a> should be
|
||||
consulted for longer descriptions.</p>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-0343"><span class="std std-ref">PEP 343: The ‘with’ statement</span></a>. The <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement is now a standard
|
||||
feature and no longer needs to be imported from the <a class="reference internal" href="../library/__future__.html#module-__future__" title="__future__: Future statement definitions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">__future__</span></code></a>.
|
||||
Also check out <a class="reference internal" href="2.6.html#new-26-context-managers"><span class="std std-ref">Writing Context Managers</span></a> and
|
||||
<a class="reference internal" href="2.6.html#new-module-contextlib"><span class="std std-ref">The contextlib module</span></a>.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-0366"><span class="std std-ref">PEP 366: Explicit Relative Imports From a Main Module</span></a>. This enhances the usefulness of the <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a>
|
||||
option when the referenced module lives in a package.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-0370"><span class="std std-ref">PEP 370: Per-user site-packages Directory</span></a>.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-0371"><span class="std std-ref">PEP 371: The multiprocessing Package</span></a>.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3101"><span class="std std-ref">PEP 3101: Advanced String Formatting</span></a>. Note: the 2.6 description mentions the
|
||||
<a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">format()</span></code></a> method for both 8-bit and Unicode strings. In 3.0,
|
||||
only the <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> type (text strings with Unicode support)
|
||||
supports this method; the <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> type does not. The plan is
|
||||
to eventually make this the only API for string formatting, and to
|
||||
start deprecating the <code class="docutils literal notranslate"><span class="pre">%</span></code> operator in Python 3.1.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3105"><span class="std std-ref">PEP 3105: print As a Function</span></a>. This is now a standard feature and no longer needs
|
||||
to be imported from <a class="reference internal" href="../library/__future__.html#module-__future__" title="__future__: Future statement definitions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">__future__</span></code></a>. More details were given above.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3110"><span class="std std-ref">PEP 3110: Exception-Handling Changes</span></a>. The <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> <em>exc</em> <code class="xref std std-keyword docutils literal notranslate"><span class="pre">as</span></code> <em>var</em>
|
||||
syntax is now standard and <code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code> <em>exc</em>, <em>var</em> is no
|
||||
longer supported. (Of course, the <code class="xref std std-keyword docutils literal notranslate"><span class="pre">as</span></code> <em>var</em> part is still
|
||||
optional.)</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3112"><span class="std std-ref">PEP 3112: Byte Literals</span></a>. The <code class="docutils literal notranslate"><span class="pre">b"..."</span></code> string literal notation (and its
|
||||
variants like <code class="docutils literal notranslate"><span class="pre">b'...'</span></code>, <code class="docutils literal notranslate"><span class="pre">b"""..."""</span></code>, and <code class="docutils literal notranslate"><span class="pre">br"..."</span></code>) now
|
||||
produces a literal of type <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3116"><span class="std std-ref">PEP 3116: New I/O Library</span></a>. The <a class="reference internal" href="../library/io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a> module is now the standard way of
|
||||
doing file I/O. The built-in <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function is now an
|
||||
alias for <a class="reference internal" href="../library/io.html#io.open" title="io.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">io.open()</span></code></a> and has additional keyword arguments
|
||||
<em>encoding</em>, <em>errors</em>, <em>newline</em> and <em>closefd</em>. Also note that an
|
||||
invalid <em>mode</em> argument now raises <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>, not
|
||||
<a class="reference internal" href="../library/exceptions.html#IOError" title="IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a>. The binary file object underlying a text file
|
||||
object can be accessed as <code class="xref py py-attr docutils literal notranslate"><span class="pre">f.buffer</span></code> (but beware that the
|
||||
text object maintains a buffer of itself in order to speed up
|
||||
the encoding and decoding operations).</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3118"><span class="std std-ref">PEP 3118: Revised Buffer Protocol</span></a>. The old builtin <code class="xref py py-func docutils literal notranslate"><span class="pre">buffer()</span></code> is now really gone;
|
||||
the new builtin <a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-func docutils literal notranslate"><span class="pre">memoryview()</span></code></a> provides (mostly) similar
|
||||
functionality.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3119"><span class="std std-ref">PEP 3119: Abstract Base Classes</span></a>. The <a class="reference internal" href="../library/abc.html#module-abc" title="abc: Abstract base classes according to PEP 3119."><code class="xref py py-mod docutils literal notranslate"><span class="pre">abc</span></code></a> module and the ABCs defined in the
|
||||
<a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> module plays a somewhat more prominent role in
|
||||
the language now, and built-in collection types like <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>
|
||||
and <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> conform to the <code class="xref py py-class docutils literal notranslate"><span class="pre">collections.MutableMapping</span></code>
|
||||
and <code class="xref py py-class docutils literal notranslate"><span class="pre">collections.MutableSequence</span></code> ABCs, respectively.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3127"><span class="std std-ref">PEP 3127: Integer Literal Support and Syntax</span></a>. As mentioned above, the new octal literal
|
||||
notation is the only one supported, and binary literals have been
|
||||
added.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3129"><span class="std std-ref">PEP 3129: Class Decorators</span></a>.</p></li>
|
||||
<li><p><a class="reference internal" href="2.6.html#pep-3141"><span class="std std-ref">PEP 3141: A Type Hierarchy for Numbers</span></a>. The <a class="reference internal" href="../library/numbers.html#module-numbers" title="numbers: Numeric abstract base classes (Complex, Real, Integral, etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">numbers</span></code></a> module is another new use of
|
||||
ABCs, defining Python’s “numeric tower”. Also note the new
|
||||
<a class="reference internal" href="../library/fractions.html#module-fractions" title="fractions: Rational numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">fractions</span></code></a> module which implements <a class="reference internal" href="../library/numbers.html#numbers.Rational" title="numbers.Rational"><code class="xref py py-class docutils literal notranslate"><span class="pre">numbers.Rational</span></code></a>.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="library-changes">
|
||||
<h2>Library Changes<a class="headerlink" href="#library-changes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Due to time constraints, this document does not exhaustively cover the
|
||||
very extensive changes to the standard library. <span class="target" id="index-17"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3108"><strong>PEP 3108</strong></a> is the
|
||||
reference for the major changes to the library. Here’s a capsule
|
||||
review:</p>
|
||||
<ul>
|
||||
<li><p>Many old modules were removed. Some, like <code class="xref py py-mod docutils literal notranslate"><span class="pre">gopherlib</span></code> (no
|
||||
longer used) and <code class="xref py py-mod docutils literal notranslate"><span class="pre">md5</span></code> (replaced by <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a>), were
|
||||
already deprecated by <span class="target" id="index-18"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0004"><strong>PEP 4</strong></a>. Others were removed as a result
|
||||
of the removal of support for various platforms such as Irix, BeOS
|
||||
and Mac OS 9 (see <span class="target" id="index-19"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0011"><strong>PEP 11</strong></a>). Some modules were also selected for
|
||||
removal in Python 3.0 due to lack of use or because a better
|
||||
replacement exists. See <span class="target" id="index-20"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3108"><strong>PEP 3108</strong></a> for an exhaustive list.</p></li>
|
||||
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">bsddb3</span></code> package was removed because its presence in the
|
||||
core standard library has proved over time to be a particular burden
|
||||
for the core developers due to testing instability and Berkeley DB’s
|
||||
release schedule. However, the package is alive and well,
|
||||
externally maintained at <a class="reference external" href="https://www.jcea.es/programacion/pybsddb.htm">https://www.jcea.es/programacion/pybsddb.htm</a>.</p></li>
|
||||
<li><p>Some modules were renamed because their old name disobeyed
|
||||
<span class="target" id="index-21"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0008"><strong>PEP 8</strong></a>, or for various other reasons. Here’s the list:</p>
|
||||
<table class="docutils align-center">
|
||||
<colgroup>
|
||||
<col style="width: 50%" />
|
||||
<col style="width: 50%" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="row-odd"><th class="head"><p>Old Name</p></th>
|
||||
<th class="head"><p>New Name</p></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="row-even"><td><p>_winreg</p></td>
|
||||
<td><p>winreg</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>ConfigParser</p></td>
|
||||
<td><p>configparser</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>copy_reg</p></td>
|
||||
<td><p>copyreg</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>Queue</p></td>
|
||||
<td><p>queue</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>SocketServer</p></td>
|
||||
<td><p>socketserver</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>markupbase</p></td>
|
||||
<td><p>_markupbase</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>repr</p></td>
|
||||
<td><p>reprlib</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>test.test_support</p></td>
|
||||
<td><p>test.support</p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</li>
|
||||
<li><p>A common pattern in Python 2.x is to have one version of a module
|
||||
implemented in pure Python, with an optional accelerated version
|
||||
implemented as a C extension; for example, <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> and
|
||||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">cPickle</span></code>. This places the burden of importing the accelerated
|
||||
version and falling back on the pure Python version on each user of
|
||||
these modules. In Python 3.0, the accelerated versions are
|
||||
considered implementation details of the pure Python versions.
|
||||
Users should always import the standard version, which attempts to
|
||||
import the accelerated version and falls back to the pure Python
|
||||
version. The <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> / <code class="xref py py-mod docutils literal notranslate"><span class="pre">cPickle</span></code> pair received this
|
||||
treatment. The <a class="reference internal" href="../library/profile.html#module-profile" title="profile: Python source profiler."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code></a> module is on the list for 3.1. The
|
||||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">StringIO</span></code> module has been turned into a class in the <a class="reference internal" href="../library/io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a>
|
||||
module.</p></li>
|
||||
<li><p>Some related modules have been grouped into packages, and usually
|
||||
the submodule names have been simplified. The resulting new
|
||||
packages are:</p>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="../library/dbm.html#module-dbm" title="dbm: Interfaces to various Unix "database" formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a> (<code class="xref py py-mod docutils literal notranslate"><span class="pre">anydbm</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">dbhash</span></code>, <a class="reference internal" href="../library/dbm.html#module-dbm" title="dbm: Interfaces to various Unix "database" formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a>,
|
||||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">dumbdbm</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">gdbm</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">whichdb</span></code>).</p></li>
|
||||
<li><p><a class="reference internal" href="../library/html.html#module-html" title="html: Helpers for manipulating HTML."><code class="xref py py-mod docutils literal notranslate"><span class="pre">html</span></code></a> (<code class="xref py py-mod docutils literal notranslate"><span class="pre">HTMLParser</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">htmlentitydefs</span></code>).</p></li>
|
||||
<li><p><a class="reference internal" href="../library/http.html#module-http" title="http: HTTP status codes and messages"><code class="xref py py-mod docutils literal notranslate"><span class="pre">http</span></code></a> (<code class="xref py py-mod docutils literal notranslate"><span class="pre">httplib</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">BaseHTTPServer</span></code>,
|
||||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">CGIHTTPServer</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">SimpleHTTPServer</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">Cookie</span></code>,
|
||||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">cookielib</span></code>).</p></li>
|
||||
<li><p><a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> (all <code class="xref py py-mod docutils literal notranslate"><span class="pre">Tkinter</span></code>-related modules except
|
||||
<a class="reference internal" href="../library/turtle.html#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a>). The target audience of <a class="reference internal" href="../library/turtle.html#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> doesn’t
|
||||
really care about <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a>. Also note that as of Python
|
||||
2.6, the functionality of <a class="reference internal" href="../library/turtle.html#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> has been greatly enhanced.</p></li>
|
||||
<li><p><a class="reference internal" href="../library/urllib.html#module-urllib" title="urllib"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a> (<a class="reference internal" href="../library/urllib.html#module-urllib" title="urllib"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib2</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">urlparse</span></code>,
|
||||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">robotparse</span></code>).</p></li>
|
||||
<li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc</span></code> (<code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpclib</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">DocXMLRPCServer</span></code>,
|
||||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">SimpleXMLRPCServer</span></code>).</p></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<p>Some other changes to standard library modules, not covered by
|
||||
<span class="target" id="index-22"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3108"><strong>PEP 3108</strong></a>:</p>
|
||||
<ul class="simple">
|
||||
<li><p>Killed <code class="xref py py-mod docutils literal notranslate"><span class="pre">sets</span></code>. Use the built-in <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-func docutils literal notranslate"><span class="pre">set()</span></code></a> class.</p></li>
|
||||
<li><p>Cleanup of the <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> module: removed <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exitfunc()</span></code>,
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_clear()</span></code>, <code class="xref py py-data docutils literal notranslate"><span class="pre">sys.exc_type</span></code>, <code class="xref py py-data docutils literal notranslate"><span class="pre">sys.exc_value</span></code>,
|
||||
<code class="xref py py-data docutils literal notranslate"><span class="pre">sys.exc_traceback</span></code>. (Note that <a class="reference internal" href="../library/sys.html#sys.last_type" title="sys.last_type"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_type</span></code></a>
|
||||
etc. remain.)</p></li>
|
||||
<li><p>Cleanup of the <a class="reference internal" href="../library/array.html#array.array" title="array.array"><code class="xref py py-class docutils literal notranslate"><span class="pre">array.array</span></code></a> type: the <code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code> and
|
||||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code> methods are gone; use <code class="xref py py-meth docutils literal notranslate"><span class="pre">fromfile()</span></code> and
|
||||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">tofile()</span></code> instead. Also, the <code class="docutils literal notranslate"><span class="pre">'c'</span></code> typecode for array is
|
||||
gone – use either <code class="docutils literal notranslate"><span class="pre">'b'</span></code> for bytes or <code class="docutils literal notranslate"><span class="pre">'u'</span></code> for Unicode
|
||||
characters.</p></li>
|
||||
<li><p>Cleanup of the <a class="reference internal" href="../library/operator.html#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a> module: removed
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">sequenceIncludes()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">isCallable()</span></code>.</p></li>
|
||||
<li><p>Cleanup of the <code class="xref py py-mod docutils literal notranslate"><span class="pre">thread</span></code> module: <code class="xref py py-func docutils literal notranslate"><span class="pre">acquire_lock()</span></code> and
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">release_lock()</span></code> are gone; use <code class="xref py py-func docutils literal notranslate"><span class="pre">acquire()</span></code> and
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">release()</span></code> instead.</p></li>
|
||||
<li><p>Cleanup of the <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a> module: removed the <code class="xref py py-func docutils literal notranslate"><span class="pre">jumpahead()</span></code> API.</p></li>
|
||||
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">new</span></code> module is gone.</p></li>
|
||||
<li><p>The functions <code class="xref py py-func docutils literal notranslate"><span class="pre">os.tmpnam()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">os.tempnam()</span></code> and
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">os.tmpfile()</span></code> have been removed in favor of the <a class="reference internal" href="../library/tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tempfile</span></code></a>
|
||||
module.</p></li>
|
||||
<li><p>The <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module has been changed to work with bytes. The
|
||||
main entry point is now <a class="reference internal" href="../library/tokenize.html#tokenize.tokenize" title="tokenize.tokenize"><code class="xref py py-func docutils literal notranslate"><span class="pre">tokenize.tokenize()</span></code></a>, instead of
|
||||
generate_tokens.</p></li>
|
||||
<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">string.letters</span></code> and its friends (<code class="xref py py-data docutils literal notranslate"><span class="pre">string.lowercase</span></code> and
|
||||
<code class="xref py py-data docutils literal notranslate"><span class="pre">string.uppercase</span></code>) are gone. Use
|
||||
<a class="reference internal" href="../library/string.html#string.ascii_letters" title="string.ascii_letters"><code class="xref py py-data docutils literal notranslate"><span class="pre">string.ascii_letters</span></code></a> etc. instead. (The reason for the
|
||||
removal is that <code class="xref py py-data docutils literal notranslate"><span class="pre">string.letters</span></code> and friends had
|
||||
locale-specific behavior, which is a bad idea for such
|
||||
attractively-named global “constants”.)</p></li>
|
||||
<li><p>Renamed module <code class="xref py py-mod docutils literal notranslate"><span class="pre">__builtin__</span></code> to <a class="reference internal" href="../library/builtins.html#module-builtins" title="builtins: The module that provides the built-in namespace."><code class="xref py py-mod docutils literal notranslate"><span class="pre">builtins</span></code></a> (removing the
|
||||
underscores, adding an ‘s’). The <code class="xref py py-data docutils literal notranslate"><span class="pre">__builtins__</span></code> variable
|
||||
found in most global namespaces is unchanged. To modify a builtin,
|
||||
you should use <a class="reference internal" href="../library/builtins.html#module-builtins" title="builtins: The module that provides the built-in namespace."><code class="xref py py-mod docutils literal notranslate"><span class="pre">builtins</span></code></a>, not <code class="xref py py-data docutils literal notranslate"><span class="pre">__builtins__</span></code>!</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="pep-3101-a-new-approach-to-string-formatting">
|
||||
<h2><span class="target" id="index-23"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3101"><strong>PEP 3101</strong></a>: A New Approach To String Formatting<a class="headerlink" href="#pep-3101-a-new-approach-to-string-formatting" title="Permalink to this headline">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p>A new system for built-in string formatting operations replaces the
|
||||
<code class="docutils literal notranslate"><span class="pre">%</span></code> string formatting operator. (However, the <code class="docutils literal notranslate"><span class="pre">%</span></code> operator is
|
||||
still supported; it will be deprecated in Python 3.1 and removed
|
||||
from the language at some later time.) Read <span class="target" id="index-24"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3101"><strong>PEP 3101</strong></a> for the full
|
||||
scoop.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="changes-to-exceptions">
|
||||
<h2>Changes To Exceptions<a class="headerlink" href="#changes-to-exceptions" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The APIs for raising and catching exception have been cleaned up and
|
||||
new powerful features added:</p>
|
||||
<ul>
|
||||
<li><p><span class="target" id="index-25"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0352"><strong>PEP 352</strong></a>: All exceptions must be derived (directly or indirectly)
|
||||
from <a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a>. This is the root of the exception
|
||||
hierarchy. This is not new as a recommendation, but the
|
||||
<em>requirement</em> to inherit from <a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a> is new. (Python
|
||||
2.6 still allowed classic classes to be raised, and placed no
|
||||
restriction on what you can catch.) As a consequence, string
|
||||
exceptions are finally truly and utterly dead.</p></li>
|
||||
<li><p>Almost all exceptions should actually derive from <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a>;
|
||||
<a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a> should only be used as a base class for
|
||||
exceptions that should only be handled at the top level, such as
|
||||
<a class="reference internal" href="../library/exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a> or <a class="reference internal" href="../library/exceptions.html#KeyboardInterrupt" title="KeyboardInterrupt"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code></a>. The recommended
|
||||
idiom for handling all exceptions except for this latter category is
|
||||
to use <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a>.</p></li>
|
||||
<li><p><code class="xref py py-exc docutils literal notranslate"><span class="pre">StandardError</span></code> was removed.</p></li>
|
||||
<li><p>Exceptions no longer behave as sequences. Use the <code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code>
|
||||
attribute instead.</p></li>
|
||||
<li><p><span class="target" id="index-26"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3109"><strong>PEP 3109</strong></a>: Raising exceptions. You must now use <code class="samp docutils literal notranslate"><span class="pre">raise</span>
|
||||
<em><span class="pre">Exception</span></em><span class="pre">(</span><em><span class="pre">args</span></em><span class="pre">)</span></code> instead of <code class="samp docutils literal notranslate"><span class="pre">raise</span> <em><span class="pre">Exception</span></em><span class="pre">,</span> <em><span class="pre">args</span></em></code>.
|
||||
Additionally, you can no longer explicitly specify a traceback;
|
||||
instead, if you <em>have</em> to do this, you can assign directly to the
|
||||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">__traceback__</span></code> attribute (see below).</p></li>
|
||||
<li><p><span class="target" id="index-27"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3110"><strong>PEP 3110</strong></a>: Catching exceptions. You must now use
|
||||
<code class="samp docutils literal notranslate"><span class="pre">except</span> <em><span class="pre">SomeException</span></em> <span class="pre">as</span> <em><span class="pre">variable</span></em></code> instead
|
||||
of <code class="samp docutils literal notranslate"><span class="pre">except</span> <em><span class="pre">SomeException</span></em><span class="pre">,</span> <em><span class="pre">variable</span></em></code>. Moreover, the
|
||||
<em>variable</em> is explicitly deleted when the <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> block
|
||||
is left.</p></li>
|
||||
<li><p><span class="target" id="index-28"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3134"><strong>PEP 3134</strong></a>: Exception chaining. There are two cases: implicit
|
||||
chaining and explicit chaining. Implicit chaining happens when an
|
||||
exception is raised in an <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> or <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a>
|
||||
handler block. This usually happens due to a bug in the handler
|
||||
block; we call this a <em>secondary</em> exception. In this case, the
|
||||
original exception (that was being handled) is saved as the
|
||||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">__context__</span></code> attribute of the secondary exception.
|
||||
Explicit chaining is invoked with this syntax:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">raise</span> <span class="n">SecondaryException</span><span class="p">()</span> <span class="kn">from</span> <span class="nn">primary_exception</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(where <em>primary_exception</em> is any expression that produces an
|
||||
exception object, probably an exception that was previously caught).
|
||||
In this case, the primary exception is stored on the
|
||||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code> attribute of the secondary exception. The
|
||||
traceback printed when an unhandled exception occurs walks the chain
|
||||
of <code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">__context__</span></code> attributes and prints a
|
||||
separate traceback for each component of the chain, with the primary
|
||||
exception at the top. (Java users may recognize this behavior.)</p>
|
||||
</li>
|
||||
<li><p><span class="target" id="index-29"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3134"><strong>PEP 3134</strong></a>: Exception objects now store their traceback as the
|
||||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">__traceback__</span></code> attribute. This means that an exception
|
||||
object now contains all the information pertaining to an exception,
|
||||
and there are fewer reasons to use <a class="reference internal" href="../library/sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a> (though the
|
||||
latter is not removed).</p></li>
|
||||
<li><p>A few exception messages are improved when Windows fails to load an
|
||||
extension module. For example, <code class="docutils literal notranslate"><span class="pre">error</span> <span class="pre">code</span> <span class="pre">193</span></code> is now <code class="docutils literal notranslate"><span class="pre">%1</span> <span class="pre">is</span>
|
||||
<span class="pre">not</span> <span class="pre">a</span> <span class="pre">valid</span> <span class="pre">Win32</span> <span class="pre">application</span></code>. Strings now deal with non-English
|
||||
locales.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="miscellaneous-other-changes">
|
||||
<h2>Miscellaneous Other Changes<a class="headerlink" href="#miscellaneous-other-changes" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="section" id="operators-and-special-methods">
|
||||
<h3>Operators And Special Methods<a class="headerlink" href="#operators-and-special-methods" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">!=</span></code> now returns the opposite of <code class="docutils literal notranslate"><span class="pre">==</span></code>, unless <code class="docutils literal notranslate"><span class="pre">==</span></code> returns
|
||||
<a class="reference internal" href="../library/constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotImplemented</span></code></a>.</p></li>
|
||||
<li><p>The concept of “unbound methods” has been removed from the language.
|
||||
When referencing a method as a class attribute, you now get a plain
|
||||
function object.</p></li>
|
||||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getslice__()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">__setslice__()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">__delslice__()</span></code>
|
||||
were killed. The syntax <code class="docutils literal notranslate"><span class="pre">a[i:j]</span></code> now translates to
|
||||
<code class="docutils literal notranslate"><span class="pre">a.__getitem__(slice(i,</span> <span class="pre">j))</span></code> (or <a class="reference internal" href="../reference/datamodel.html#object.__setitem__" title="object.__setitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__setitem__()</span></code></a> or
|
||||
<a class="reference internal" href="../reference/datamodel.html#object.__delitem__" title="object.__delitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__delitem__()</span></code></a>, when used as an assignment or deletion target,
|
||||
respectively).</p></li>
|
||||
<li><p><span class="target" id="index-30"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3114"><strong>PEP 3114</strong></a>: the standard <a class="reference internal" href="../library/functions.html#next" title="next"><code class="xref py py-meth docutils literal notranslate"><span class="pre">next()</span></code></a> method has been renamed to
|
||||
<a class="reference internal" href="../library/stdtypes.html#iterator.__next__" title="iterator.__next__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__next__()</span></code></a>.</p></li>
|
||||
<li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">__oct__()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">__hex__()</span></code> special methods are removed
|
||||
– <a class="reference internal" href="../library/functions.html#oct" title="oct"><code class="xref py py-func docutils literal notranslate"><span class="pre">oct()</span></code></a> and <a class="reference internal" href="../library/functions.html#hex" title="hex"><code class="xref py py-func docutils literal notranslate"><span class="pre">hex()</span></code></a> use <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> now to convert
|
||||
the argument to an integer.</p></li>
|
||||
<li><p>Removed support for <code class="xref py py-attr docutils literal notranslate"><span class="pre">__members__</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">__methods__</span></code>.</p></li>
|
||||
<li><p>The function attributes named <code class="xref py py-attr docutils literal notranslate"><span class="pre">func_X</span></code> have been renamed to
|
||||
use the <code class="xref py py-data docutils literal notranslate"><span class="pre">__X__</span></code> form, freeing up these names in the function
|
||||
attribute namespace for user-defined attributes. To wit,
|
||||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">func_closure</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">func_code</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">func_defaults</span></code>,
|
||||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">func_dict</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">func_doc</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">func_globals</span></code>,
|
||||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">func_name</span></code> were renamed to <code class="xref py py-attr docutils literal notranslate"><span class="pre">__closure__</span></code>,
|
||||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">__code__</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">__defaults__</span></code>, <a class="reference internal" href="../library/stdtypes.html#object.__dict__" title="object.__dict__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__dict__</span></code></a>,
|
||||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">__doc__</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">__globals__</span></code>, <a class="reference internal" href="../library/stdtypes.html#definition.__name__" title="definition.__name__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__name__</span></code></a>,
|
||||
respectively.</p></li>
|
||||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">__nonzero__()</span></code> is now <a class="reference internal" href="../reference/datamodel.html#object.__bool__" title="object.__bool__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__bool__()</span></code></a>.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="builtins">
|
||||
<h3>Builtins<a class="headerlink" href="#builtins" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p><span class="target" id="index-31"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3135"><strong>PEP 3135</strong></a>: New <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a>. You can now invoke <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a>
|
||||
without arguments and (assuming this is in a regular instance method
|
||||
defined inside a <a class="reference internal" href="../reference/compound_stmts.html#class"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">class</span></code></a> statement) the right class and
|
||||
instance will automatically be chosen. With arguments, the behavior
|
||||
of <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a> is unchanged.</p></li>
|
||||
<li><p><span class="target" id="index-32"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3111"><strong>PEP 3111</strong></a>: <code class="xref py py-func docutils literal notranslate"><span class="pre">raw_input()</span></code> was renamed to <a class="reference internal" href="../library/functions.html#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a>. That
|
||||
is, the new <a class="reference internal" href="../library/functions.html#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a> function reads a line from
|
||||
<a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a> and returns it with the trailing newline stripped.
|
||||
It raises <a class="reference internal" href="../library/exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">EOFError</span></code></a> if the input is terminated prematurely.
|
||||
To get the old behavior of <a class="reference internal" href="../library/functions.html#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a>, use <code class="docutils literal notranslate"><span class="pre">eval(input())</span></code>.</p></li>
|
||||
<li><p>A new built-in function <a class="reference internal" href="../library/functions.html#next" title="next"><code class="xref py py-func docutils literal notranslate"><span class="pre">next()</span></code></a> was added to call the
|
||||
<a class="reference internal" href="../library/stdtypes.html#iterator.__next__" title="iterator.__next__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__next__()</span></code></a> method on an object.</p></li>
|
||||
<li><p>The <a class="reference internal" href="../library/functions.html#round" title="round"><code class="xref py py-func docutils literal notranslate"><span class="pre">round()</span></code></a> function rounding strategy and return type have
|
||||
changed. Exact halfway cases are now rounded to the nearest even
|
||||
result instead of away from zero. (For example, <code class="docutils literal notranslate"><span class="pre">round(2.5)</span></code> now
|
||||
returns <code class="docutils literal notranslate"><span class="pre">2</span></code> rather than <code class="docutils literal notranslate"><span class="pre">3</span></code>.) <code class="docutils literal notranslate"><span class="pre">round(x[,</span> <span class="pre">n])</span></code> now
|
||||
delegates to <code class="docutils literal notranslate"><span class="pre">x.__round__([n])</span></code> instead of always returning a
|
||||
float. It generally returns an integer when called with a single
|
||||
argument and a value of the same type as <code class="docutils literal notranslate"><span class="pre">x</span></code> when called with two
|
||||
arguments.</p></li>
|
||||
<li><p>Moved <code class="xref py py-func docutils literal notranslate"><span class="pre">intern()</span></code> to <a class="reference internal" href="../library/sys.html#sys.intern" title="sys.intern"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.intern()</span></code></a>.</p></li>
|
||||
<li><p>Removed: <code class="xref py py-func docutils literal notranslate"><span class="pre">apply()</span></code>. Instead of <code class="docutils literal notranslate"><span class="pre">apply(f,</span> <span class="pre">args)</span></code> use
|
||||
<code class="docutils literal notranslate"><span class="pre">f(*args)</span></code>.</p></li>
|
||||
<li><p>Removed <a class="reference internal" href="../library/functions.html#callable" title="callable"><code class="xref py py-func docutils literal notranslate"><span class="pre">callable()</span></code></a>. Instead of <code class="docutils literal notranslate"><span class="pre">callable(f)</span></code> you can use
|
||||
<code class="docutils literal notranslate"><span class="pre">isinstance(f,</span> <span class="pre">collections.Callable)</span></code>. The <code class="xref py py-func docutils literal notranslate"><span class="pre">operator.isCallable()</span></code>
|
||||
function is also gone.</p></li>
|
||||
<li><p>Removed <code class="xref py py-func docutils literal notranslate"><span class="pre">coerce()</span></code>. This function no longer serves a purpose
|
||||
now that classic classes are gone.</p></li>
|
||||
<li><p>Removed <code class="xref py py-func docutils literal notranslate"><span class="pre">execfile()</span></code>. Instead of <code class="docutils literal notranslate"><span class="pre">execfile(fn)</span></code> use
|
||||
<code class="docutils literal notranslate"><span class="pre">exec(open(fn).read())</span></code>.</p></li>
|
||||
<li><p>Removed the <code class="xref py py-class docutils literal notranslate"><span class="pre">file</span></code> type. Use <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>. There are now several
|
||||
different kinds of streams that open can return in the <a class="reference internal" href="../library/io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a> module.</p></li>
|
||||
<li><p>Removed <code class="xref py py-func docutils literal notranslate"><span class="pre">reduce()</span></code>. Use <a class="reference internal" href="../library/functools.html#functools.reduce" title="functools.reduce"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.reduce()</span></code></a> if you really
|
||||
need it; however, 99 percent of the time an explicit <a class="reference internal" href="../reference/compound_stmts.html#for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code></a>
|
||||
loop is more readable.</p></li>
|
||||
<li><p>Removed <code class="xref py py-func docutils literal notranslate"><span class="pre">reload()</span></code>. Use <a class="reference internal" href="../library/imp.html#imp.reload" title="imp.reload"><code class="xref py py-func docutils literal notranslate"><span class="pre">imp.reload()</span></code></a>.</p></li>
|
||||
<li><p>Removed. <code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.has_key()</span></code> – use the <a class="reference internal" href="../reference/expressions.html#in"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">in</span></code></a> operator
|
||||
instead.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="build-and-c-api-changes">
|
||||
<h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Due to time constraints, here is a <em>very</em> incomplete list of changes
|
||||
to the C API.</p>
|
||||
<ul class="simple">
|
||||
<li><p>Support for several platforms was dropped, including but not limited
|
||||
to Mac OS 9, BeOS, RISCOS, Irix, and Tru64.</p></li>
|
||||
<li><p><span class="target" id="index-33"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3118"><strong>PEP 3118</strong></a>: New Buffer API.</p></li>
|
||||
<li><p><span class="target" id="index-34"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3121"><strong>PEP 3121</strong></a>: Extension Module Initialization & Finalization.</p></li>
|
||||
<li><p><span class="target" id="index-35"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3123"><strong>PEP 3123</strong></a>: Making <a class="reference internal" href="../c-api/structures.html#c.PyObject_HEAD" title="PyObject_HEAD"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyObject_HEAD</span></code></a> conform to standard C.</p></li>
|
||||
<li><p>No more C API support for restricted execution.</p></li>
|
||||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Coerce()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_CoerceEx()</span></code>,
|
||||
<code class="xref c c-func docutils literal notranslate"><span class="pre">PyMember_Get()</span></code>, and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyMember_Set()</span></code> C APIs are removed.</p></li>
|
||||
<li><p>New C API <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleNoBlock()</span></code></a>, works like
|
||||
<a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModule()</span></code></a> but won’t block on the import lock
|
||||
(returning an error instead).</p></li>
|
||||
<li><p>Renamed the boolean conversion C-level slot and method:
|
||||
<code class="docutils literal notranslate"><span class="pre">nb_nonzero</span></code> is now <code class="docutils literal notranslate"><span class="pre">nb_bool</span></code>.</p></li>
|
||||
<li><p>Removed <code class="xref c c-macro docutils literal notranslate"><span class="pre">METH_OLDARGS</span></code> and <code class="xref c c-macro docutils literal notranslate"><span class="pre">WITH_CYCLE_GC</span></code> from the C API.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="performance">
|
||||
<h2>Performance<a class="headerlink" href="#performance" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The net result of the 3.0 generalizations is that Python 3.0 runs the
|
||||
pystone benchmark around 10% slower than Python 2.5. Most likely the
|
||||
biggest cause is the removal of special-casing for small integers.
|
||||
There’s room for improvement, but it will happen after 3.0 is
|
||||
released!</p>
|
||||
</div>
|
||||
<div class="section" id="porting-to-python-3-0">
|
||||
<h2>Porting To Python 3.0<a class="headerlink" href="#porting-to-python-3-0" title="Permalink to this headline">¶</a></h2>
|
||||
<p>For porting existing Python 2.5 or 2.6 source code to Python 3.0, the
|
||||
best strategy is the following:</p>
|
||||
<ol class="arabic simple" start="0">
|
||||
<li><p>(Prerequisite:) Start with excellent test coverage.</p></li>
|
||||
<li><p>Port to Python 2.6. This should be no more work than the average
|
||||
port from Python 2.x to Python 2.(x+1). Make sure all your tests
|
||||
pass.</p></li>
|
||||
<li><p>(Still using 2.6:) Turn on the <code class="xref std std-option docutils literal notranslate"><span class="pre">-3</span></code> command line switch.
|
||||
This enables warnings about features that will be removed (or
|
||||
change) in 3.0. Run your test suite again, and fix code that you
|
||||
get warnings about until there are no warnings left, and all your
|
||||
tests still pass.</p></li>
|
||||
<li><p>Run the <code class="docutils literal notranslate"><span class="pre">2to3</span></code> source-to-source translator over your source code
|
||||
tree. (See <a class="reference internal" href="../library/2to3.html#to3-reference"><span class="std std-ref">2to3 - Automated Python 2 to 3 code translation</span></a> for more on this tool.) Run the
|
||||
result of the translation under Python 3.0. Manually fix up any
|
||||
remaining issues, fixing problems until all tests pass again.</p></li>
|
||||
</ol>
|
||||
<p>It is not recommended to try to write source code that runs unchanged
|
||||
under both Python 2.6 and 3.0; you’d have to use a very contorted
|
||||
coding style, e.g. avoiding <code class="docutils literal notranslate"><span class="pre">print</span></code> statements, metaclasses,
|
||||
and much more. If you are maintaining a library that needs to support
|
||||
both Python 2.6 and Python 3.0, the best approach is to modify step 3
|
||||
above by editing the 2.6 version of the source code and running the
|
||||
<code class="docutils literal notranslate"><span class="pre">2to3</span></code> translator again, rather than editing the 3.0 version of the
|
||||
source code.</p>
|
||||
<p>For porting C extensions to Python 3.0, please see <a class="reference internal" href="../howto/cporting.html#cporting-howto"><span class="std std-ref">Porting Extension Modules to Python 3</span></a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="../contents.html">Table of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">What’s New In Python 3.0</a><ul>
|
||||
<li><a class="reference internal" href="#common-stumbling-blocks">Common Stumbling Blocks</a><ul>
|
||||
<li><a class="reference internal" href="#print-is-a-function">Print Is A Function</a></li>
|
||||
<li><a class="reference internal" href="#views-and-iterators-instead-of-lists">Views And Iterators Instead Of Lists</a></li>
|
||||
<li><a class="reference internal" href="#ordering-comparisons">Ordering Comparisons</a></li>
|
||||
<li><a class="reference internal" href="#integers">Integers</a></li>
|
||||
<li><a class="reference internal" href="#text-vs-data-instead-of-unicode-vs-8-bit">Text Vs. Data Instead Of Unicode Vs. 8-bit</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#overview-of-syntax-changes">Overview Of Syntax Changes</a><ul>
|
||||
<li><a class="reference internal" href="#new-syntax">New Syntax</a></li>
|
||||
<li><a class="reference internal" href="#changed-syntax">Changed Syntax</a></li>
|
||||
<li><a class="reference internal" href="#removed-syntax">Removed Syntax</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#changes-already-present-in-python-2-6">Changes Already Present In Python 2.6</a></li>
|
||||
<li><a class="reference internal" href="#library-changes">Library Changes</a></li>
|
||||
<li><a class="reference internal" href="#pep-3101-a-new-approach-to-string-formatting"><strong>PEP 3101</strong>: A New Approach To String Formatting</a></li>
|
||||
<li><a class="reference internal" href="#changes-to-exceptions">Changes To Exceptions</a></li>
|
||||
<li><a class="reference internal" href="#miscellaneous-other-changes">Miscellaneous Other Changes</a><ul>
|
||||
<li><a class="reference internal" href="#operators-and-special-methods">Operators And Special Methods</a></li>
|
||||
<li><a class="reference internal" href="#builtins">Builtins</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li><a class="reference internal" href="#performance">Performance</a></li>
|
||||
<li><a class="reference internal" href="#porting-to-python-3-0">Porting To Python 3.0</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="3.1.html"
|
||||
title="previous chapter">What’s New In Python 3.1</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="2.7.html"
|
||||
title="next chapter">What’s New in Python 2.7</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<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/3.7/Doc/whatsnew/3.0.rst"
|
||||
rel="nofollow">Show Source
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</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="2.7.html" title="What’s New in Python 2.7"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="3.1.html" title="What’s New In Python 3.1"
|
||||
>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>
|
||||
<span class="language_switcher_placeholder">en</span>
|
||||
<span class="version_switcher_placeholder">3.7.4</span>
|
||||
<a href="../index.html">Documentation </a> »
|
||||
</li>
|
||||
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> »</li>
|
||||
<li class="right">
|
||||
|
||||
|
||||
<div class="inline-search" style="display: none" role="search">
|
||||
<form class="inline-search" action="../search.html" method="get">
|
||||
<input placeholder="Quick search" type="text" name="q" />
|
||||
<input type="submit" value="Go" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||||
|
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer">
|
||||
© <a href="../copyright.html">Copyright</a> 2001-2019, 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 Jul 13, 2019.
|
||||
<a href="../bugs.html">Found a bug</a>?
|
||||
<br />
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
678
python-3.7.4-docs-html/whatsnew/3.1.html
Normal file
678
python-3.7.4-docs-html/whatsnew/3.1.html
Normal file
@@ -0,0 +1,678 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>What’s New In Python 3.1 — Python 3.7.4 documentation</title>
|
||||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></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/language_data.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
||||
|
||||
<link rel="search" type="application/opensearchdescription+xml"
|
||||
title="Search within Python 3.7.4 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="What’s New In Python 3.0" href="3.0.html" />
|
||||
<link rel="prev" title="What’s New In Python 3.2" href="3.2.html" />
|
||||
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
|
||||
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.1.html" />
|
||||
|
||||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||||
<script type="text/javascript" src="../_static/switchers.js"></script>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
@media only screen {
|
||||
table.full-width-table {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
</head><body>
|
||||
|
||||
<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="3.0.html" title="What’s New In Python 3.0"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="3.2.html" title="What’s New In Python 3.2"
|
||||
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>
|
||||
<span class="language_switcher_placeholder">en</span>
|
||||
<span class="version_switcher_placeholder">3.7.4</span>
|
||||
<a href="../index.html">Documentation </a> »
|
||||
</li>
|
||||
|
||||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> »</li>
|
||||
<li class="right">
|
||||
|
||||
|
||||
<div class="inline-search" style="display: none" role="search">
|
||||
<form class="inline-search" action="../search.html" method="get">
|
||||
<input placeholder="Quick search" type="text" name="q" />
|
||||
<input type="submit" value="Go" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||||
|
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="what-s-new-in-python-3-1">
|
||||
<h1>What’s New In Python 3.1<a class="headerlink" href="#what-s-new-in-python-3-1" title="Permalink to this headline">¶</a></h1>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Author</dt>
|
||||
<dd class="field-odd"><p>Raymond Hettinger</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<p>This article explains the new features in Python 3.1, compared to 3.0.</p>
|
||||
<div class="section" id="pep-372-ordered-dictionaries">
|
||||
<h2>PEP 372: Ordered Dictionaries<a class="headerlink" href="#pep-372-ordered-dictionaries" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Regular Python dictionaries iterate over key/value pairs in arbitrary order.
|
||||
Over the years, a number of authors have written alternative implementations
|
||||
that remember the order that the keys were originally inserted. Based on
|
||||
the experiences from those implementations, a new
|
||||
<a class="reference internal" href="../library/collections.html#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.OrderedDict</span></code></a> class has been introduced.</p>
|
||||
<p>The OrderedDict API is substantially the same as regular dictionaries
|
||||
but will iterate over keys and values in a guaranteed order depending on
|
||||
when a key was first inserted. If a new entry overwrites an existing entry,
|
||||
the original insertion position is left unchanged. Deleting an entry and
|
||||
reinserting it will move it to the end.</p>
|
||||
<p>The standard library now supports use of ordered dictionaries in several
|
||||
modules. The <a class="reference internal" href="../library/configparser.html#module-configparser" title="configparser: Configuration file parser."><code class="xref py py-mod docutils literal notranslate"><span class="pre">configparser</span></code></a> module uses them by default. This lets
|
||||
configuration files be read, modified, and then written back in their original
|
||||
order. The <em>_asdict()</em> method for <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">collections.namedtuple()</span></code></a> now
|
||||
returns an ordered dictionary with the values appearing in the same order as
|
||||
the underlying tuple indices. The <a class="reference internal" href="../library/json.html#module-json" title="json: Encode and decode the JSON format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code></a> module is being built-out with
|
||||
an <em>object_pairs_hook</em> to allow OrderedDicts to be built by the decoder.
|
||||
Support was also added for third-party tools like <a class="reference external" href="http://pyyaml.org/">PyYAML</a>.</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0372"><strong>PEP 372</strong></a> - Ordered Dictionaries</dt><dd><p>PEP written by Armin Ronacher and Raymond Hettinger. Implementation
|
||||
written by Raymond Hettinger.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="pep-378-format-specifier-for-thousands-separator">
|
||||
<h2>PEP 378: Format Specifier for Thousands Separator<a class="headerlink" href="#pep-378-format-specifier-for-thousands-separator" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The built-in <a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a> function and the <a class="reference internal" href="../library/stdtypes.html#str.format" title="str.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.format()</span></code></a> method use
|
||||
a mini-language that now includes a simple, non-locale aware way to format
|
||||
a number with a thousands separator. That provides a way to humanize a
|
||||
program’s output, improving its professional appearance and readability:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">format</span><span class="p">(</span><span class="mi">1234567</span><span class="p">,</span> <span class="s1">',d'</span><span class="p">)</span>
|
||||
<span class="go">'1,234,567'</span>
|
||||
<span class="gp">>>> </span><span class="nb">format</span><span class="p">(</span><span class="mf">1234567.89</span><span class="p">,</span> <span class="s1">',.2f'</span><span class="p">)</span>
|
||||
<span class="go">'1,234,567.89'</span>
|
||||
<span class="gp">>>> </span><span class="nb">format</span><span class="p">(</span><span class="mf">12345.6</span> <span class="o">+</span> <span class="mf">8901234.12</span><span class="n">j</span><span class="p">,</span> <span class="s1">',f'</span><span class="p">)</span>
|
||||
<span class="go">'12,345.600000+8,901,234.120000j'</span>
|
||||
<span class="gp">>>> </span><span class="nb">format</span><span class="p">(</span><span class="n">Decimal</span><span class="p">(</span><span class="s1">'1234567.89'</span><span class="p">),</span> <span class="s1">',f'</span><span class="p">)</span>
|
||||
<span class="go">'1,234,567.89'</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The supported types are <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>, <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>, <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a>
|
||||
and <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a>.</p>
|
||||
<p>Discussions are underway about how to specify alternative separators
|
||||
like dots, spaces, apostrophes, or underscores. Locale-aware applications
|
||||
should use the existing <em>n</em> format specifier which already has some support
|
||||
for thousands separators.</p>
|
||||
<div class="admonition seealso">
|
||||
<p class="admonition-title">See also</p>
|
||||
<dl class="simple">
|
||||
<dt><span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0378"><strong>PEP 378</strong></a> - Format Specifier for Thousands Separator</dt><dd><p>PEP written by Raymond Hettinger and implemented by Eric Smith and
|
||||
Mark Dickinson.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="other-language-changes">
|
||||
<h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Some smaller changes made to the core Python language are:</p>
|
||||
<ul>
|
||||
<li><p>Directories and zip archives containing a <code class="file docutils literal notranslate"><span class="pre">__main__.py</span></code>
|
||||
file can now be executed directly by passing their name to the
|
||||
interpreter. The directory/zipfile is automatically inserted as the
|
||||
first entry in sys.path. (Suggestion and initial patch by Andy Chu;
|
||||
revised patch by Phillip J. Eby and Nick Coghlan; <a class="reference external" href="https://bugs.python.org/issue1739468">bpo-1739468</a>.)</p></li>
|
||||
<li><p>The <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-func docutils literal notranslate"><span class="pre">int()</span></code></a> type gained a <code class="docutils literal notranslate"><span class="pre">bit_length</span></code> method that returns the
|
||||
number of bits necessary to represent its argument in binary:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">n</span> <span class="o">=</span> <span class="mi">37</span>
|
||||
<span class="gp">>>> </span><span class="nb">bin</span><span class="p">(</span><span class="mi">37</span><span class="p">)</span>
|
||||
<span class="go">'0b100101'</span>
|
||||
<span class="gp">>>> </span><span class="n">n</span><span class="o">.</span><span class="n">bit_length</span><span class="p">()</span>
|
||||
<span class="go">6</span>
|
||||
<span class="gp">>>> </span><span class="n">n</span> <span class="o">=</span> <span class="mi">2</span><span class="o">**</span><span class="mi">123</span><span class="o">-</span><span class="mi">1</span>
|
||||
<span class="gp">>>> </span><span class="n">n</span><span class="o">.</span><span class="n">bit_length</span><span class="p">()</span>
|
||||
<span class="go">123</span>
|
||||
<span class="gp">>>> </span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">bit_length</span><span class="p">()</span>
|
||||
<span class="go">124</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(Contributed by Fredrik Johansson, Victor Stinner, Raymond Hettinger,
|
||||
and Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue3439">bpo-3439</a>.)</p>
|
||||
</li>
|
||||
<li><p>The fields in <a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a> strings can now be automatically
|
||||
numbered:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s1">'Sir </span><span class="si">{}</span><span class="s1"> of </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">'Gallahad'</span><span class="p">,</span> <span class="s1">'Camelot'</span><span class="p">)</span>
|
||||
<span class="go">'Sir Gallahad of Camelot'</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Formerly, the string would have required numbered fields such as:
|
||||
<code class="docutils literal notranslate"><span class="pre">'Sir</span> <span class="pre">{0}</span> <span class="pre">of</span> <span class="pre">{1}'</span></code>.</p>
|
||||
<p>(Contributed by Eric Smith; <a class="reference external" href="https://bugs.python.org/issue5237">bpo-5237</a>.)</p>
|
||||
</li>
|
||||
<li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">string.maketrans()</span></code> function is deprecated and is replaced by new
|
||||
static methods, <a class="reference internal" href="../library/stdtypes.html#bytes.maketrans" title="bytes.maketrans"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytes.maketrans()</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytearray.maketrans" title="bytearray.maketrans"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytearray.maketrans()</span></code></a>.
|
||||
This change solves the confusion around which types were supported by the
|
||||
<a class="reference internal" href="../library/string.html#module-string" title="string: Common string operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">string</span></code></a> module. Now, <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>, and
|
||||
<a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> each have their own <strong>maketrans</strong> and <strong>translate</strong>
|
||||
methods with intermediate translation tables of the appropriate type.</p>
|
||||
<p>(Contributed by Georg Brandl; <a class="reference external" href="https://bugs.python.org/issue5675">bpo-5675</a>.)</p>
|
||||
</li>
|
||||
<li><p>The syntax of the <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement now allows multiple context
|
||||
managers in a single statement:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'mylog.txt'</span><span class="p">)</span> <span class="k">as</span> <span class="n">infile</span><span class="p">,</span> <span class="nb">open</span><span class="p">(</span><span class="s1">'a.out'</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span> <span class="k">as</span> <span class="n">outfile</span><span class="p">:</span>
|
||||
<span class="gp">... </span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">infile</span><span class="p">:</span>
|
||||
<span class="gp">... </span> <span class="k">if</span> <span class="s1">'<critical>'</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
|
||||
<span class="gp">... </span> <span class="n">outfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>With the new syntax, the <code class="xref py py-func docutils literal notranslate"><span class="pre">contextlib.nested()</span></code> function is no longer
|
||||
needed and is now deprecated.</p>
|
||||
<p>(Contributed by Georg Brandl and Mattias Brändström;
|
||||
<a class="reference external" href="https://codereview.appspot.com/53094">appspot issue 53094</a>.)</p>
|
||||
</li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">round(x,</span> <span class="pre">n)</span></code> now returns an integer if <em>x</em> is an integer.
|
||||
Previously it returned a float:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">round</span><span class="p">(</span><span class="mi">1123</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">)</span>
|
||||
<span class="go">1100</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(Contributed by Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue4707">bpo-4707</a>.)</p>
|
||||
</li>
|
||||
<li><p>Python now uses David Gay’s algorithm for finding the shortest floating
|
||||
point representation that doesn’t change its value. This should help
|
||||
mitigate some of the confusion surrounding binary floating point
|
||||
numbers.</p>
|
||||
<p>The significance is easily seen with a number like <code class="docutils literal notranslate"><span class="pre">1.1</span></code> which does not
|
||||
have an exact equivalent in binary floating point. Since there is no exact
|
||||
equivalent, an expression like <code class="docutils literal notranslate"><span class="pre">float('1.1')</span></code> evaluates to the nearest
|
||||
representable value which is <code class="docutils literal notranslate"><span class="pre">0x1.199999999999ap+0</span></code> in hex or
|
||||
<code class="docutils literal notranslate"><span class="pre">1.100000000000000088817841970012523233890533447265625</span></code> in decimal. That
|
||||
nearest value was and still is used in subsequent floating point
|
||||
calculations.</p>
|
||||
<p>What is new is how the number gets displayed. Formerly, Python used a
|
||||
simple approach. The value of <code class="docutils literal notranslate"><span class="pre">repr(1.1)</span></code> was computed as <code class="docutils literal notranslate"><span class="pre">format(1.1,</span>
|
||||
<span class="pre">'.17g')</span></code> which evaluated to <code class="docutils literal notranslate"><span class="pre">'1.1000000000000001'</span></code>. The advantage of
|
||||
using 17 digits was that it relied on IEEE-754 guarantees to assure that
|
||||
<code class="docutils literal notranslate"><span class="pre">eval(repr(1.1))</span></code> would round-trip exactly to its original value. The
|
||||
disadvantage is that many people found the output to be confusing (mistaking
|
||||
intrinsic limitations of binary floating point representation as being a
|
||||
problem with Python itself).</p>
|
||||
<p>The new algorithm for <code class="docutils literal notranslate"><span class="pre">repr(1.1)</span></code> is smarter and returns <code class="docutils literal notranslate"><span class="pre">'1.1'</span></code>.
|
||||
Effectively, it searches all equivalent string representations (ones that
|
||||
get stored with the same underlying float value) and returns the shortest
|
||||
representation.</p>
|
||||
<p>The new algorithm tends to emit cleaner representations when possible, but
|
||||
it does not change the underlying values. So, it is still the case that
|
||||
<code class="docutils literal notranslate"><span class="pre">1.1</span> <span class="pre">+</span> <span class="pre">2.2</span> <span class="pre">!=</span> <span class="pre">3.3</span></code> even though the representations may suggest otherwise.</p>
|
||||
<p>The new algorithm depends on certain features in the underlying floating
|
||||
point implementation. If the required features are not found, the old
|
||||
algorithm will continue to be used. Also, the text pickle protocols
|
||||
assure cross-platform portability by using the old algorithm.</p>
|
||||
<p>(Contributed by Eric Smith and Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue1580">bpo-1580</a>)</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="new-improved-and-deprecated-modules">
|
||||
<h2>New, Improved, and Deprecated Modules<a class="headerlink" href="#new-improved-and-deprecated-modules" title="Permalink to this headline">¶</a></h2>
|
||||
<ul>
|
||||
<li><p>Added a <a class="reference internal" href="../library/collections.html#collections.Counter" title="collections.Counter"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.Counter</span></code></a> class to support convenient
|
||||
counting of unique items in a sequence or iterable:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Counter</span><span class="p">([</span><span class="s1">'red'</span><span class="p">,</span> <span class="s1">'blue'</span><span class="p">,</span> <span class="s1">'red'</span><span class="p">,</span> <span class="s1">'green'</span><span class="p">,</span> <span class="s1">'blue'</span><span class="p">,</span> <span class="s1">'blue'</span><span class="p">])</span>
|
||||
<span class="go">Counter({'blue': 3, 'red': 2, 'green': 1})</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(Contributed by Raymond Hettinger; <a class="reference external" href="https://bugs.python.org/issue1696199">bpo-1696199</a>.)</p>
|
||||
</li>
|
||||
<li><p>Added a new module, <a class="reference internal" href="../library/tkinter.ttk.html#module-tkinter.ttk" title="tkinter.ttk: Tk themed widget set"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.ttk</span></code></a> for access to the Tk themed widget set.
|
||||
The basic idea of ttk is to separate, to the extent possible, the code
|
||||
implementing a widget’s behavior from the code implementing its appearance.</p>
|
||||
<p>(Contributed by Guilherme Polo; <a class="reference external" href="https://bugs.python.org/issue2983">bpo-2983</a>.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/gzip.html#gzip.GzipFile" title="gzip.GzipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">gzip.GzipFile</span></code></a> and <a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> classes now support
|
||||
the context management protocol:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># Automatically close file after writing</span>
|
||||
<span class="gp">>>> </span><span class="k">with</span> <span class="n">gzip</span><span class="o">.</span><span class="n">GzipFile</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">"wb"</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
|
||||
<span class="gp">... </span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="sa">b</span><span class="s2">"xxx"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(Contributed by Antoine Pitrou.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/decimal.html#module-decimal" title="decimal: Implementation of the General Decimal Arithmetic Specification."><code class="xref py py-mod docutils literal notranslate"><span class="pre">decimal</span></code></a> module now supports methods for creating a
|
||||
decimal object from a binary <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>. The conversion is
|
||||
exact but can sometimes be surprising:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Decimal</span><span class="o">.</span><span class="n">from_float</span><span class="p">(</span><span class="mf">1.1</span><span class="p">)</span>
|
||||
<span class="go">Decimal('1.100000000000000088817841970012523233890533447265625')</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The long decimal result shows the actual binary fraction being
|
||||
stored for <em>1.1</em>. The fraction has many digits because <em>1.1</em> cannot
|
||||
be exactly represented in binary.</p>
|
||||
<p>(Contributed by Raymond Hettinger and Mark Dickinson.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/itertools.html#module-itertools" title="itertools: Functions creating iterators for efficient looping."><code class="xref py py-mod docutils literal notranslate"><span class="pre">itertools</span></code></a> module grew two new functions. The
|
||||
<a class="reference internal" href="../library/itertools.html#itertools.combinations_with_replacement" title="itertools.combinations_with_replacement"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.combinations_with_replacement()</span></code></a> function is one of
|
||||
four for generating combinatorics including permutations and Cartesian
|
||||
products. The <a class="reference internal" href="../library/itertools.html#itertools.compress" title="itertools.compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.compress()</span></code></a> function mimics its namesake
|
||||
from APL. Also, the existing <a class="reference internal" href="../library/itertools.html#itertools.count" title="itertools.count"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.count()</span></code></a> function now has
|
||||
an optional <em>step</em> argument and can accept any type of counting
|
||||
sequence including <a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">fractions.Fraction</span></code></a> and
|
||||
<a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a>:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="p">[</span><span class="n">p</span><span class="o">+</span><span class="n">q</span> <span class="k">for</span> <span class="n">p</span><span class="p">,</span><span class="n">q</span> <span class="ow">in</span> <span class="n">combinations_with_replacement</span><span class="p">(</span><span class="s1">'LOVE'</span><span class="p">,</span> <span class="mi">2</span><span class="p">)]</span>
|
||||
<span class="go">['LL', 'LO', 'LV', 'LE', 'OO', 'OV', 'OE', 'VV', 'VE', 'EE']</span>
|
||||
|
||||
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">compress</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span> <span class="n">selectors</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]))</span>
|
||||
<span class="go">[2, 3, 5, 7]</span>
|
||||
|
||||
<span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">count</span><span class="p">(</span><span class="n">start</span><span class="o">=</span><span class="n">Fraction</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">step</span><span class="o">=</span><span class="n">Fraction</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span>
|
||||
<span class="gp">>>> </span><span class="p">[</span><span class="nb">next</span><span class="p">(</span><span class="n">c</span><span class="p">),</span> <span class="nb">next</span><span class="p">(</span><span class="n">c</span><span class="p">),</span> <span class="nb">next</span><span class="p">(</span><span class="n">c</span><span class="p">),</span> <span class="nb">next</span><span class="p">(</span><span class="n">c</span><span class="p">)]</span>
|
||||
<span class="go">[Fraction(1, 2), Fraction(2, 3), Fraction(5, 6), Fraction(1, 1)]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(Contributed by Raymond Hettinger.)</p>
|
||||
</li>
|
||||
<li><p><a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">collections.namedtuple()</span></code></a> now supports a keyword argument
|
||||
<em>rename</em> which lets invalid fieldnames be automatically converted to
|
||||
positional names in the form _0, _1, etc. This is useful when
|
||||
the field names are being created by an external source such as a
|
||||
CSV header, SQL field list, or user input:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">query</span> <span class="o">=</span> <span class="nb">input</span><span class="p">()</span>
|
||||
<span class="go">SELECT region, dept, count(*) FROM main GROUPBY region, dept</span>
|
||||
|
||||
<span class="gp">>>> </span><span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">query</span><span class="p">)</span>
|
||||
<span class="gp">>>> </span><span class="n">query_fields</span> <span class="o">=</span> <span class="p">[</span><span class="n">desc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">desc</span> <span class="ow">in</span> <span class="n">cursor</span><span class="o">.</span><span class="n">description</span><span class="p">]</span>
|
||||
<span class="gp">>>> </span><span class="n">UserQuery</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s1">'UserQuery'</span><span class="p">,</span> <span class="n">query_fields</span><span class="p">,</span> <span class="n">rename</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||||
<span class="gp">>>> </span><span class="n">pprint</span><span class="o">.</span><span class="n">pprint</span><span class="p">([</span><span class="n">UserQuery</span><span class="p">(</span><span class="o">*</span><span class="n">row</span><span class="p">)</span> <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">cursor</span><span class="p">])</span>
|
||||
<span class="go">[UserQuery(region='South', dept='Shipping', _2=185),</span>
|
||||
<span class="go"> UserQuery(region='North', dept='Accounting', _2=37),</span>
|
||||
<span class="go"> UserQuery(region='West', dept='Sales', _2=419)]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(Contributed by Raymond Hettinger; <a class="reference external" href="https://bugs.python.org/issue1818">bpo-1818</a>.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.sub()</span></code></a>, <a class="reference internal" href="../library/re.html#re.subn" title="re.subn"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.subn()</span></code></a> and <a class="reference internal" href="../library/re.html#re.split" title="re.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.split()</span></code></a> functions now
|
||||
accept a flags parameter.</p>
|
||||
<p>(Contributed by Gregory Smith.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> module now implements a simple <a class="reference internal" href="../library/logging.handlers.html#logging.NullHandler" title="logging.NullHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">logging.NullHandler</span></code></a>
|
||||
class for applications that are not using logging but are calling
|
||||
library code that does. Setting-up a null handler will suppress
|
||||
spurious warnings such as “No handlers could be found for logger foo”:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">h</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">NullHandler</span><span class="p">()</span>
|
||||
<span class="gp">>>> </span><span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">h</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(Contributed by Vinay Sajip; <a class="reference external" href="https://bugs.python.org/issue4384">bpo-4384</a>).</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/runpy.html#module-runpy" title="runpy: Locate and run Python modules without importing them first."><code class="xref py py-mod docutils literal notranslate"><span class="pre">runpy</span></code></a> module which supports the <code class="docutils literal notranslate"><span class="pre">-m</span></code> command line switch
|
||||
now supports the execution of packages by looking for and executing
|
||||
a <code class="docutils literal notranslate"><span class="pre">__main__</span></code> submodule when a package name is supplied.</p>
|
||||
<p>(Contributed by Andi Vajda; <a class="reference external" href="https://bugs.python.org/issue4195">bpo-4195</a>.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> module can now access and display source code loaded via
|
||||
<a class="reference internal" href="../library/zipimport.html#module-zipimport" title="zipimport: support for importing Python modules from ZIP archives."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code></a> (or any other conformant <span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0302"><strong>PEP 302</strong></a> loader).</p>
|
||||
<p>(Contributed by Alexander Belopolsky; <a class="reference external" href="https://bugs.python.org/issue4201">bpo-4201</a>.)</p>
|
||||
</li>
|
||||
<li><p><a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-class docutils literal notranslate"><span class="pre">functools.partial</span></code></a> objects can now be pickled.</p></li>
|
||||
</ul>
|
||||
<blockquote>
|
||||
<div><p>(Suggested by Antoine Pitrou and Jesse Noller. Implemented by
|
||||
Jack Diederich; <a class="reference external" href="https://bugs.python.org/issue5228">bpo-5228</a>.)</p>
|
||||
</div></blockquote>
|
||||
<ul>
|
||||
<li><p>Add <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> help topics for symbols so that <code class="docutils literal notranslate"><span class="pre">help('@')</span></code>
|
||||
works as expected in the interactive environment.</p>
|
||||
<p>(Contributed by David Laban; <a class="reference external" href="https://bugs.python.org/issue4739">bpo-4739</a>.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> module now supports skipping individual tests or classes
|
||||
of tests. And it supports marking a test as an expected failure, a test that
|
||||
is known to be broken, but shouldn’t be counted as a failure on a
|
||||
TestResult:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">TestGizmo</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
|
||||
|
||||
<span class="nd">@unittest</span><span class="o">.</span><span class="n">skipUnless</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">platform</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"win"</span><span class="p">),</span> <span class="s2">"requires Windows"</span><span class="p">)</span>
|
||||
<span class="k">def</span> <span class="nf">test_gizmo_on_windows</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
|
||||
<span class="nd">@unittest</span><span class="o">.</span><span class="n">expectedFailure</span>
|
||||
<span class="k">def</span> <span class="nf">test_gimzo_without_required_library</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Also, tests for exceptions have been builtout to work with context managers
|
||||
using the <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">test_division_by_zero</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">assertRaises</span><span class="p">(</span><span class="ne">ZeroDivisionError</span><span class="p">):</span>
|
||||
<span class="n">x</span> <span class="o">/</span> <span class="mi">0</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>In addition, several new assertion methods were added including
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">assertSetEqual()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">assertDictEqual()</span></code>,
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">assertDictContainsSubset()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">assertListEqual()</span></code>,
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">assertTupleEqual()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">assertSequenceEqual()</span></code>,
|
||||
<code class="xref py py-func docutils literal notranslate"><span class="pre">assertRaisesRegexp()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">assertIsNone()</span></code>,
|
||||
and <code class="xref py py-func docutils literal notranslate"><span class="pre">assertIsNotNone()</span></code>.</p>
|
||||
<p>(Contributed by Benjamin Peterson and Antoine Pitrou.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a> module has three new constants for the <code class="xref py py-meth docutils literal notranslate"><span class="pre">seek()</span></code>
|
||||
method <code class="xref py py-data docutils literal notranslate"><span class="pre">SEEK_SET</span></code>, <code class="xref py py-data docutils literal notranslate"><span class="pre">SEEK_CUR</span></code>, and <code class="xref py py-data docutils literal notranslate"><span class="pre">SEEK_END</span></code>.</p></li>
|
||||
<li><p>The <a class="reference internal" href="../library/sys.html#sys.version_info" title="sys.version_info"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.version_info</span></code></a> tuple is now a named tuple:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">sys</span><span class="o">.</span><span class="n">version_info</span>
|
||||
<span class="go">sys.version_info(major=3, minor=1, micro=0, releaselevel='alpha', serial=2)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(Contributed by Ross Light; <a class="reference external" href="https://bugs.python.org/issue4285">bpo-4285</a>.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/nntplib.html#module-nntplib" title="nntplib: NNTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">nntplib</span></code></a> and <a class="reference internal" href="../library/imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a> modules now support IPv6.</p>
|
||||
<p>(Contributed by Derek Morr; <a class="reference external" href="https://bugs.python.org/issue1655">bpo-1655</a> and <a class="reference external" href="https://bugs.python.org/issue1664">bpo-1664</a>.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> module has been adapted for better interoperability with
|
||||
Python 2.x when used with protocol 2 or lower. The reorganization of the
|
||||
standard library changed the formal reference for many objects. For
|
||||
example, <code class="docutils literal notranslate"><span class="pre">__builtin__.set</span></code> in Python 2 is called <code class="docutils literal notranslate"><span class="pre">builtins.set</span></code> in Python
|
||||
3. This change confounded efforts to share data between different versions of
|
||||
Python. But now when protocol 2 or lower is selected, the pickler will
|
||||
automatically use the old Python 2 names for both loading and dumping. This
|
||||
remapping is turned-on by default but can be disabled with the <em>fix_imports</em>
|
||||
option:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">}</span>
|
||||
<span class="gp">>>> </span><span class="n">pickle</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
|
||||
<span class="go">b'c__builtin__\nset\np0\n((lp1\nL1L\naL2L\naL3L\natp2\nRp3\n.'</span>
|
||||
<span class="gp">>>> </span><span class="n">pickle</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">fix_imports</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
||||
<span class="go">b'cbuiltins\nset\np0\n((lp1\nL1L\naL2L\naL3L\natp2\nRp3\n.'</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>An unfortunate but unavoidable side-effect of this change is that protocol 2
|
||||
pickles produced by Python 3.1 won’t be readable with Python 3.0. The latest
|
||||
pickle protocol, protocol 3, should be used when migrating data between
|
||||
Python 3.x implementations, as it doesn’t attempt to remain compatible with
|
||||
Python 2.x.</p>
|
||||
<p>(Contributed by Alexandre Vassalotti and Antoine Pitrou, <a class="reference external" href="https://bugs.python.org/issue6137">bpo-6137</a>.)</p>
|
||||
</li>
|
||||
<li><p>A new module, <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> was added. It provides a complete, portable,
|
||||
pure Python reference implementation of the <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> statement and its
|
||||
counterpart, the <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> function. It represents a substantial
|
||||
step forward in documenting and defining the actions that take place during
|
||||
imports.</p>
|
||||
<p>(Contributed by Brett Cannon.)</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="optimizations">
|
||||
<h2>Optimizations<a class="headerlink" href="#optimizations" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Major performance enhancements have been added:</p>
|
||||
<ul>
|
||||
<li><p>The new I/O library (as defined in <span class="target" id="index-3"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3116"><strong>PEP 3116</strong></a>) was mostly written in
|
||||
Python and quickly proved to be a problematic bottleneck in Python 3.0.
|
||||
In Python 3.1, the I/O library has been entirely rewritten in C and is
|
||||
2 to 20 times faster depending on the task at hand. The pure Python
|
||||
version is still available for experimentation purposes through
|
||||
the <code class="docutils literal notranslate"><span class="pre">_pyio</span></code> module.</p>
|
||||
<p>(Contributed by Amaury Forgeot d’Arc and Antoine Pitrou.)</p>
|
||||
</li>
|
||||
<li><p>Added a heuristic so that tuples and dicts containing only untrackable objects
|
||||
are not tracked by the garbage collector. This can reduce the size of
|
||||
collections and therefore the garbage collection overhead on long-running
|
||||
programs, depending on their particular use of datatypes.</p>
|
||||
<p>(Contributed by Antoine Pitrou, <a class="reference external" href="https://bugs.python.org/issue4688">bpo-4688</a>.)</p>
|
||||
</li>
|
||||
<li><p>Enabling a configure option named <code class="docutils literal notranslate"><span class="pre">--with-computed-gotos</span></code>
|
||||
on compilers that support it (notably: gcc, SunPro, icc), the bytecode
|
||||
evaluation loop is compiled with a new dispatch mechanism which gives
|
||||
speedups of up to 20%, depending on the system, the compiler, and
|
||||
the benchmark.</p>
|
||||
<p>(Contributed by Antoine Pitrou along with a number of other participants,
|
||||
<a class="reference external" href="https://bugs.python.org/issue4753">bpo-4753</a>).</p>
|
||||
</li>
|
||||
<li><p>The decoding of UTF-8, UTF-16 and LATIN-1 is now two to four times
|
||||
faster.</p>
|
||||
<p>(Contributed by Antoine Pitrou and Amaury Forgeot d’Arc, <a class="reference external" href="https://bugs.python.org/issue4868">bpo-4868</a>.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../library/json.html#module-json" title="json: Encode and decode the JSON format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code></a> module now has a C extension to substantially improve
|
||||
its performance. In addition, the API was modified so that json works
|
||||
only with <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, not with <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>. That change makes the
|
||||
module closely match the <a class="reference external" href="http://json.org/">JSON specification</a>
|
||||
which is defined in terms of Unicode.</p>
|
||||
<p>(Contributed by Bob Ippolito and converted to Py3.1 by Antoine Pitrou
|
||||
and Benjamin Peterson; <a class="reference external" href="https://bugs.python.org/issue4136">bpo-4136</a>.)</p>
|
||||
</li>
|
||||
<li><p>Unpickling now interns the attribute names of pickled objects. This saves
|
||||
memory and allows pickles to be smaller.</p>
|
||||
<p>(Contributed by Jake McGuire and Antoine Pitrou; <a class="reference external" href="https://bugs.python.org/issue5084">bpo-5084</a>.)</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="idle">
|
||||
<h2>IDLE<a class="headerlink" href="#idle" title="Permalink to this headline">¶</a></h2>
|
||||
<ul>
|
||||
<li><p>IDLE’s format menu now provides an option to strip trailing whitespace
|
||||
from a source file.</p>
|
||||
<p>(Contributed by Roger D. Serwy; <a class="reference external" href="https://bugs.python.org/issue5150">bpo-5150</a>.)</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="build-and-c-api-changes">
|
||||
<h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Changes to Python’s build process and to the C API include:</p>
|
||||
<ul>
|
||||
<li><p>Integers are now stored internally either in base 2**15 or in base
|
||||
2**30, the base being determined at build time. Previously, they
|
||||
were always stored in base 2**15. Using base 2**30 gives
|
||||
significant performance improvements on 64-bit machines, but
|
||||
benchmark results on 32-bit machines have been mixed. Therefore,
|
||||
the default is to use base 2**30 on 64-bit machines and base 2**15
|
||||
on 32-bit machines; on Unix, there’s a new configure option
|
||||
<code class="docutils literal notranslate"><span class="pre">--enable-big-digits</span></code> that can be used to override this default.</p>
|
||||
<p>Apart from the performance improvements this change should be invisible to
|
||||
end users, with one exception: for testing and debugging purposes there’s a
|
||||
new <a class="reference internal" href="../library/sys.html#sys.int_info" title="sys.int_info"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.int_info</span></code></a> that provides information about the
|
||||
internal format, giving the number of bits per digit and the size in bytes
|
||||
of the C type used to store each digit:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">sys</span>
|
||||
<span class="gp">>>> </span><span class="n">sys</span><span class="o">.</span><span class="n">int_info</span>
|
||||
<span class="go">sys.int_info(bits_per_digit=30, sizeof_digit=4)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>(Contributed by Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue4258">bpo-4258</a>.)</p>
|
||||
</li>
|
||||
<li><p>The <a class="reference internal" href="../c-api/long.html#c.PyLong_AsUnsignedLongLong" title="PyLong_AsUnsignedLongLong"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_AsUnsignedLongLong()</span></code></a> function now handles a negative
|
||||
<em>pylong</em> by raising <a class="reference internal" href="../library/exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a> instead of <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>.</p>
|
||||
<p>(Contributed by Mark Dickinson and Lisandro Dalcrin; <a class="reference external" href="https://bugs.python.org/issue5175">bpo-5175</a>.)</p>
|
||||
</li>
|
||||
<li><p>Deprecated <code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Int()</span></code>. Use <a class="reference internal" href="../c-api/number.html#c.PyNumber_Long" title="PyNumber_Long"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Long()</span></code></a> instead.</p>
|
||||
<p>(Contributed by Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue4910">bpo-4910</a>.)</p>
|
||||
</li>
|
||||
<li><p>Added a new <a class="reference internal" href="../c-api/conversion.html#c.PyOS_string_to_double" title="PyOS_string_to_double"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_string_to_double()</span></code></a> function to replace the
|
||||
deprecated functions <code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_ascii_strtod()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_ascii_atof()</span></code>.</p>
|
||||
<p>(Contributed by Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue5914">bpo-5914</a>.)</p>
|
||||
</li>
|
||||
<li><p>Added <a class="reference internal" href="../c-api/capsule.html#c.PyCapsule" title="PyCapsule"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCapsule</span></code></a> as a replacement for the <code class="xref c c-type docutils literal notranslate"><span class="pre">PyCObject</span></code> API.
|
||||
The principal difference is that the new type has a well defined interface
|
||||
for passing typing safety information and a less complicated signature
|
||||
for calling a destructor. The old type had a problematic API and is now
|
||||
deprecated.</p>
|
||||
<p>(Contributed by Larry Hastings; <a class="reference external" href="https://bugs.python.org/issue5630">bpo-5630</a>.)</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="porting-to-python-3-1">
|
||||
<h2>Porting to Python 3.1<a class="headerlink" href="#porting-to-python-3-1" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This section lists previously described changes and other bugfixes
|
||||
that may require changes to your code:</p>
|
||||
<ul>
|
||||
<li><p>The new floating point string representations can break existing doctests.
|
||||
For example:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">e</span><span class="p">():</span>
|
||||
<span class="sd">'''Compute the base of natural logarithms.</span>
|
||||
|
||||
<span class="sd"> >>> e()</span>
|
||||
<span class="sd"> 2.7182818284590451</span>
|
||||
|
||||
<span class="sd"> '''</span>
|
||||
<span class="k">return</span> <span class="nb">sum</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">math</span><span class="o">.</span><span class="n">factorial</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">reversed</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">30</span><span class="p">)))</span>
|
||||
|
||||
<span class="n">doctest</span><span class="o">.</span><span class="n">testmod</span><span class="p">()</span>
|
||||
|
||||
<span class="o">**********************************************************************</span>
|
||||
<span class="n">Failed</span> <span class="n">example</span><span class="p">:</span>
|
||||
<span class="n">e</span><span class="p">()</span>
|
||||
<span class="n">Expected</span><span class="p">:</span>
|
||||
<span class="mf">2.7182818284590451</span>
|
||||
<span class="n">Got</span><span class="p">:</span>
|
||||
<span class="mf">2.718281828459045</span>
|
||||
<span class="o">**********************************************************************</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</li>
|
||||
<li><p>The automatic name remapping in the pickle module for protocol 2 or lower can
|
||||
make Python 3.1 pickles unreadable in Python 3.0. One solution is to use
|
||||
protocol 3. Another solution is to set the <em>fix_imports</em> option to <code class="docutils literal notranslate"><span class="pre">False</span></code>.
|
||||
See the discussion above for more details.</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h3><a href="../contents.html">Table of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">What’s New In Python 3.1</a><ul>
|
||||
<li><a class="reference internal" href="#pep-372-ordered-dictionaries">PEP 372: Ordered Dictionaries</a></li>
|
||||
<li><a class="reference internal" href="#pep-378-format-specifier-for-thousands-separator">PEP 378: Format Specifier for Thousands Separator</a></li>
|
||||
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
|
||||
<li><a class="reference internal" href="#new-improved-and-deprecated-modules">New, Improved, and Deprecated Modules</a></li>
|
||||
<li><a class="reference internal" href="#optimizations">Optimizations</a></li>
|
||||
<li><a class="reference internal" href="#idle">IDLE</a></li>
|
||||
<li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li><a class="reference internal" href="#porting-to-python-3-1">Porting to Python 3.1</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>Previous topic</h4>
|
||||
<p class="topless"><a href="3.2.html"
|
||||
title="previous chapter">What’s New In Python 3.2</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="3.0.html"
|
||||
title="next chapter">What’s New In Python 3.0</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<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/3.7/Doc/whatsnew/3.1.rst"
|
||||
rel="nofollow">Show Source
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</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="3.0.html" title="What’s New In Python 3.0"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="3.2.html" title="What’s New In Python 3.2"
|
||||
>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>
|
||||
<span class="language_switcher_placeholder">en</span>
|
||||
<span class="version_switcher_placeholder">3.7.4</span>
|
||||
<a href="../index.html">Documentation </a> »
|
||||
</li>
|
||||
|
||||
<li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> »</li>
|
||||
<li class="right">
|
||||
|
||||
|
||||
<div class="inline-search" style="display: none" role="search">
|
||||
<form class="inline-search" action="../search.html" method="get">
|
||||
<input placeholder="Quick search" type="text" name="q" />
|
||||
<input type="submit" value="Go" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||||
|
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer">
|
||||
© <a href="../copyright.html">Copyright</a> 2001-2019, 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 Jul 13, 2019.
|
||||
<a href="../bugs.html">Found a bug</a>?
|
||||
<br />
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
2724
python-3.7.4-docs-html/whatsnew/3.2.html
Normal file
2724
python-3.7.4-docs-html/whatsnew/3.2.html
Normal file
File diff suppressed because it is too large
Load Diff
2527
python-3.7.4-docs-html/whatsnew/3.3.html
Normal file
2527
python-3.7.4-docs-html/whatsnew/3.3.html
Normal file
File diff suppressed because it is too large
Load Diff
2332
python-3.7.4-docs-html/whatsnew/3.4.html
Normal file
2332
python-3.7.4-docs-html/whatsnew/3.4.html
Normal file
File diff suppressed because it is too large
Load Diff
2421
python-3.7.4-docs-html/whatsnew/3.5.html
Normal file
2421
python-3.7.4-docs-html/whatsnew/3.5.html
Normal file
File diff suppressed because it is too large
Load Diff
2265
python-3.7.4-docs-html/whatsnew/3.6.html
Normal file
2265
python-3.7.4-docs-html/whatsnew/3.6.html
Normal file
File diff suppressed because it is too large
Load Diff
2356
python-3.7.4-docs-html/whatsnew/3.7.html
Normal file
2356
python-3.7.4-docs-html/whatsnew/3.7.html
Normal file
File diff suppressed because it is too large
Load Diff
14343
python-3.7.4-docs-html/whatsnew/changelog.html
Normal file
14343
python-3.7.4-docs-html/whatsnew/changelog.html
Normal file
File diff suppressed because it is too large
Load Diff
564
python-3.7.4-docs-html/whatsnew/index.html
Normal file
564
python-3.7.4-docs-html/whatsnew/index.html
Normal file
@@ -0,0 +1,564 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>What’s New in Python — Python 3.7.4 documentation</title>
|
||||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||||
|
||||
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></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/language_data.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
||||
|
||||
<link rel="search" type="application/opensearchdescription+xml"
|
||||
title="Search within Python 3.7.4 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="What’s New In Python 3.7" href="3.7.html" />
|
||||
<link rel="prev" title="Python Documentation contents" href="../contents.html" />
|
||||
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
|
||||
<link rel="canonical" href="https://docs.python.org/3/whatsnew/index.html" />
|
||||
|
||||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||||
<script type="text/javascript" src="../_static/switchers.js"></script>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
@media only screen {
|
||||
table.full-width-table {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
</head><body>
|
||||
|
||||
<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="3.7.html" title="What’s New In Python 3.7"
|
||||
accesskey="N">next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="../contents.html" title="Python Documentation contents"
|
||||
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>
|
||||
<span class="language_switcher_placeholder">en</span>
|
||||
<span class="version_switcher_placeholder">3.7.4</span>
|
||||
<a href="../index.html">Documentation </a> »
|
||||
</li>
|
||||
|
||||
<li class="right">
|
||||
|
||||
|
||||
<div class="inline-search" style="display: none" role="search">
|
||||
<form class="inline-search" action="../search.html" method="get">
|
||||
<input placeholder="Quick search" type="text" name="q" />
|
||||
<input type="submit" value="Go" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||||
|
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="what-s-new-in-python">
|
||||
<span id="whatsnew-index"></span><h1>What’s New in Python<a class="headerlink" href="#what-s-new-in-python" title="Permalink to this headline">¶</a></h1>
|
||||
<p>The “What’s New in Python” series of essays takes tours through the most
|
||||
important changes between major Python versions. They are a “must read” for
|
||||
anyone wishing to stay up-to-date after a new release.</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="3.7.html">What’s New In Python 3.7</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#summary-release-highlights">Summary – Release Highlights</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#new-features">New Features</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#new-modules">New Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#improved-modules">Improved Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#c-api-changes">C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#build-changes">Build Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#optimizations">Optimizations</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#other-cpython-implementation-changes">Other CPython Implementation Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#deprecated-python-behavior">Deprecated Python Behavior</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#deprecated-python-modules-functions-and-methods">Deprecated Python modules, functions and methods</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#deprecated-functions-and-types-of-the-c-api">Deprecated functions and types of the C API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#platform-support-removals">Platform Support Removals</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#api-and-feature-removals">API and Feature Removals</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#module-removals">Module Removals</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#windows-only-changes">Windows-only Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#porting-to-python-3-7">Porting to Python 3.7</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#notable-changes-in-python-3-7-1">Notable changes in Python 3.7.1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.7.html#notable-changes-in-python-3-7-2">Notable changes in Python 3.7.2</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="3.6.html">What’s New In Python 3.6</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#summary-release-highlights">Summary – Release highlights</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#new-features">New Features</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#new-modules">New Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#improved-modules">Improved Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#optimizations">Optimizations</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#other-improvements">Other Improvements</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#deprecated">Deprecated</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#removed">Removed</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#porting-to-python-3-6">Porting to Python 3.6</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#notable-changes-in-python-3-6-2">Notable changes in Python 3.6.2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#notable-changes-in-python-3-6-4">Notable changes in Python 3.6.4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#notable-changes-in-python-3-6-5">Notable changes in Python 3.6.5</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.6.html#notable-changes-in-python-3-6-7">Notable changes in Python 3.6.7</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="3.5.html">What’s New In Python 3.5</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#summary-release-highlights">Summary – Release highlights</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#new-features">New Features</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#new-modules">New Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#improved-modules">Improved Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#other-module-level-changes">Other module-level changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#optimizations">Optimizations</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#deprecated">Deprecated</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#removed">Removed</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#porting-to-python-3-5">Porting to Python 3.5</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.5.html#notable-changes-in-python-3-5-4">Notable changes in Python 3.5.4</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="3.4.html">What’s New In Python 3.4</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.4.html#summary-release-highlights">Summary – Release Highlights</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.4.html#new-features">New Features</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.4.html#new-modules">New Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.4.html#improved-modules">Improved Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.4.html#cpython-implementation-changes">CPython Implementation Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.4.html#deprecated">Deprecated</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.4.html#removed">Removed</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.4.html#porting-to-python-3-4">Porting to Python 3.4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.4.html#changed-in-3-4-3">Changed in 3.4.3</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="3.3.html">What’s New In Python 3.3</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#summary-release-highlights">Summary – Release highlights</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-405-virtual-environments">PEP 405: Virtual Environments</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-420-implicit-namespace-packages">PEP 420: Implicit Namespace Packages</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-3118-new-memoryview-implementation-and-buffer-protocol-documentation">PEP 3118: New memoryview implementation and buffer protocol documentation</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-393-flexible-string-representation">PEP 393: Flexible String Representation</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-397-python-launcher-for-windows">PEP 397: Python Launcher for Windows</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy">PEP 3151: Reworking the OS and IO exception hierarchy</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-380-syntax-for-delegating-to-a-subgenerator">PEP 380: Syntax for Delegating to a Subgenerator</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-409-suppressing-exception-context">PEP 409: Suppressing exception context</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-414-explicit-unicode-literals">PEP 414: Explicit Unicode literals</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-3155-qualified-name-for-classes-and-functions">PEP 3155: Qualified name for classes and functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-412-key-sharing-dictionary">PEP 412: Key-Sharing Dictionary</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-362-function-signature-object">PEP 362: Function Signature Object</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#pep-421-adding-sys-implementation">PEP 421: Adding sys.implementation</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#using-importlib-as-the-implementation-of-import">Using importlib as the Implementation of Import</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#a-finer-grained-import-lock">A Finer-Grained Import Lock</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#builtin-functions-and-types">Builtin functions and types</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#new-modules">New Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#improved-modules">Improved Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#optimizations">Optimizations</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#deprecated">Deprecated</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.3.html#porting-to-python-3-3">Porting to Python 3.3</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="3.2.html">What’s New In Python 3.2</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#pep-384-defining-a-stable-abi">PEP 384: Defining a Stable ABI</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#pep-389-argparse-command-line-parsing-module">PEP 389: Argparse Command Line Parsing Module</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#pep-391-dictionary-based-configuration-for-logging">PEP 391: Dictionary Based Configuration for Logging</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#pep-3148-the-concurrent-futures-module">PEP 3148: The <code class="docutils literal notranslate"><span class="pre">concurrent.futures</span></code> module</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#pep-3147-pyc-repository-directories">PEP 3147: PYC Repository Directories</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#pep-3149-abi-version-tagged-so-files">PEP 3149: ABI Version Tagged .so Files</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#pep-3333-python-web-server-gateway-interface-v1-0-1">PEP 3333: Python Web Server Gateway Interface v1.0.1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#new-improved-and-deprecated-modules">New, Improved, and Deprecated Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#multi-threading">Multi-threading</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#optimizations">Optimizations</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#unicode">Unicode</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#codecs">Codecs</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#documentation">Documentation</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#idle">IDLE</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#code-repository">Code Repository</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.2.html#porting-to-python-3-2">Porting to Python 3.2</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="3.1.html">What’s New In Python 3.1</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.1.html#pep-372-ordered-dictionaries">PEP 372: Ordered Dictionaries</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.1.html#pep-378-format-specifier-for-thousands-separator">PEP 378: Format Specifier for Thousands Separator</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.1.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.1.html#new-improved-and-deprecated-modules">New, Improved, and Deprecated Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.1.html#optimizations">Optimizations</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.1.html#idle">IDLE</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.1.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.1.html#porting-to-python-3-1">Porting to Python 3.1</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="3.0.html">What’s New In Python 3.0</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#common-stumbling-blocks">Common Stumbling Blocks</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#overview-of-syntax-changes">Overview Of Syntax Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#changes-already-present-in-python-2-6">Changes Already Present In Python 2.6</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#library-changes">Library Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#pep-3101-a-new-approach-to-string-formatting"><strong>PEP 3101</strong>: A New Approach To String Formatting</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#changes-to-exceptions">Changes To Exceptions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#miscellaneous-other-changes">Miscellaneous Other Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#performance">Performance</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="3.0.html#porting-to-python-3-0">Porting To Python 3.0</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="2.7.html">What’s New in Python 2.7</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#the-future-for-python-2-x">The Future for Python 2.x</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#changes-to-the-handling-of-deprecation-warnings">Changes to the Handling of Deprecation Warnings</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#python-3-1-features">Python 3.1 Features</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#pep-372-adding-an-ordered-dictionary-to-collections">PEP 372: Adding an Ordered Dictionary to collections</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#pep-378-format-specifier-for-thousands-separator">PEP 378: Format Specifier for Thousands Separator</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#pep-389-the-argparse-module-for-parsing-command-lines">PEP 389: The argparse Module for Parsing Command Lines</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#pep-391-dictionary-based-configuration-for-logging">PEP 391: Dictionary-Based Configuration For Logging</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#pep-3106-dictionary-views">PEP 3106: Dictionary Views</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#pep-3137-the-memoryview-object">PEP 3137: The memoryview Object</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#new-and-improved-modules">New and Improved Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#other-changes-and-fixes">Other Changes and Fixes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#porting-to-python-2-7">Porting to Python 2.7</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#new-features-added-to-python-2-7-maintenance-releases">New Features Added to Python 2.7 Maintenance Releases</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.7.html#acknowledgements">Acknowledgements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="2.6.html">What’s New in Python 2.6</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#python-3-0">Python 3.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#changes-to-the-development-process">Changes to the Development Process</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-343-the-with-statement">PEP 343: The ‘with’ statement</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-366-explicit-relative-imports-from-a-main-module">PEP 366: Explicit Relative Imports From a Main Module</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-370-per-user-site-packages-directory">PEP 370: Per-user <code class="docutils literal notranslate"><span class="pre">site-packages</span></code> Directory</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-371-the-multiprocessing-package">PEP 371: The <code class="docutils literal notranslate"><span class="pre">multiprocessing</span></code> Package</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3101-advanced-string-formatting">PEP 3101: Advanced String Formatting</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3105-print-as-a-function">PEP 3105: <code class="docutils literal notranslate"><span class="pre">print</span></code> As a Function</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3110-exception-handling-changes">PEP 3110: Exception-Handling Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3112-byte-literals">PEP 3112: Byte Literals</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3116-new-i-o-library">PEP 3116: New I/O Library</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3118-revised-buffer-protocol">PEP 3118: Revised Buffer Protocol</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3119-abstract-base-classes">PEP 3119: Abstract Base Classes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3127-integer-literal-support-and-syntax">PEP 3127: Integer Literal Support and Syntax</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3129-class-decorators">PEP 3129: Class Decorators</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#pep-3141-a-type-hierarchy-for-numbers">PEP 3141: A Type Hierarchy for Numbers</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#new-and-improved-modules">New and Improved Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#deprecations-and-removals">Deprecations and Removals</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#porting-to-python-2-6">Porting to Python 2.6</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.6.html#acknowledgements">Acknowledgements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="2.5.html">What’s New in Python 2.5</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-308-conditional-expressions">PEP 308: Conditional Expressions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-309-partial-function-application">PEP 309: Partial Function Application</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-314-metadata-for-python-software-packages-v1-1">PEP 314: Metadata for Python Software Packages v1.1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-328-absolute-and-relative-imports">PEP 328: Absolute and Relative Imports</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-338-executing-modules-as-scripts">PEP 338: Executing Modules as Scripts</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-341-unified-try-except-finally">PEP 341: Unified try/except/finally</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-342-new-generator-features">PEP 342: New Generator Features</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-343-the-with-statement">PEP 343: The ‘with’ statement</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-352-exceptions-as-new-style-classes">PEP 352: Exceptions as New-Style Classes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-353-using-ssize-t-as-the-index-type">PEP 353: Using ssize_t as the index type</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#pep-357-the-index-method">PEP 357: The ‘__index__’ method</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#new-improved-and-removed-modules">New, Improved, and Removed Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#porting-to-python-2-5">Porting to Python 2.5</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.5.html#acknowledgements">Acknowledgements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="2.4.html">What’s New in Python 2.4</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-218-built-in-set-objects">PEP 218: Built-In Set Objects</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-237-unifying-long-integers-and-integers">PEP 237: Unifying Long Integers and Integers</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-289-generator-expressions">PEP 289: Generator Expressions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-292-simpler-string-substitutions">PEP 292: Simpler String Substitutions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-318-decorators-for-functions-and-methods">PEP 318: Decorators for Functions and Methods</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-322-reverse-iteration">PEP 322: Reverse Iteration</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-324-new-subprocess-module">PEP 324: New subprocess Module</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-327-decimal-data-type">PEP 327: Decimal Data Type</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-328-multi-line-imports">PEP 328: Multi-line Imports</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#pep-331-locale-independent-float-string-conversions">PEP 331: Locale-Independent Float/String Conversions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#new-improved-and-deprecated-modules">New, Improved, and Deprecated Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#porting-to-python-2-4">Porting to Python 2.4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.4.html#acknowledgements">Acknowledgements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="2.3.html">What’s New in Python 2.3</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-218-a-standard-set-datatype">PEP 218: A Standard Set Datatype</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-255-simple-generators">PEP 255: Simple Generators</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-263-source-code-encodings">PEP 263: Source Code Encodings</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-273-importing-modules-from-zip-archives">PEP 273: Importing Modules from ZIP Archives</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-277-unicode-file-name-support-for-windows-nt">PEP 277: Unicode file name support for Windows NT</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-278-universal-newline-support">PEP 278: Universal Newline Support</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-279-enumerate">PEP 279: enumerate()</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-282-the-logging-package">PEP 282: The logging Package</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-285-a-boolean-type">PEP 285: A Boolean Type</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-293-codec-error-handling-callbacks">PEP 293: Codec Error Handling Callbacks</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-301-package-index-and-metadata-for-distutils">PEP 301: Package Index and Metadata for Distutils</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-302-new-import-hooks">PEP 302: New Import Hooks</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-305-comma-separated-files">PEP 305: Comma-separated Files</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pep-307-pickle-enhancements">PEP 307: Pickle Enhancements</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#extended-slices">Extended Slices</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#other-language-changes">Other Language Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#new-improved-and-deprecated-modules">New, Improved, and Deprecated Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#pymalloc-a-specialized-object-allocator">Pymalloc: A Specialized Object Allocator</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#build-and-c-api-changes">Build and C API Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#other-changes-and-fixes">Other Changes and Fixes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#porting-to-python-2-3">Porting to Python 2.3</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.3.html#acknowledgements">Acknowledgements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="2.2.html">What’s New in Python 2.2</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#introduction">Introduction</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#peps-252-and-253-type-and-class-changes">PEPs 252 and 253: Type and Class Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#pep-234-iterators">PEP 234: Iterators</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#pep-255-simple-generators">PEP 255: Simple Generators</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#pep-237-unifying-long-integers-and-integers">PEP 237: Unifying Long Integers and Integers</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#pep-238-changing-the-division-operator">PEP 238: Changing the Division Operator</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#unicode-changes">Unicode Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#pep-227-nested-scopes">PEP 227: Nested Scopes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#new-and-improved-modules">New and Improved Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#interpreter-changes-and-fixes">Interpreter Changes and Fixes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#other-changes-and-fixes">Other Changes and Fixes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.2.html#acknowledgements">Acknowledgements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="2.1.html">What’s New in Python 2.1</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#introduction">Introduction</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-227-nested-scopes">PEP 227: Nested Scopes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-236-future-directives">PEP 236: __future__ Directives</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-207-rich-comparisons">PEP 207: Rich Comparisons</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-230-warning-framework">PEP 230: Warning Framework</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-229-new-build-system">PEP 229: New Build System</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-205-weak-references">PEP 205: Weak References</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-232-function-attributes">PEP 232: Function Attributes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-235-importing-modules-on-case-insensitive-platforms">PEP 235: Importing Modules on Case-Insensitive Platforms</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-217-interactive-display-hook">PEP 217: Interactive Display Hook</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-208-new-coercion-model">PEP 208: New Coercion Model</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#pep-241-metadata-in-python-packages">PEP 241: Metadata in Python Packages</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#new-and-improved-modules">New and Improved Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#other-changes-and-fixes">Other Changes and Fixes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.1.html#acknowledgements">Acknowledgements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="2.0.html">What’s New in Python 2.0</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#introduction">Introduction</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#what-about-python-1-6">What About Python 1.6?</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#new-development-process">New Development Process</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#unicode">Unicode</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#list-comprehensions">List Comprehensions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#augmented-assignment">Augmented Assignment</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#string-methods">String Methods</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#garbage-collection-of-cycles">Garbage Collection of Cycles</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#other-core-changes">Other Core Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#porting-to-2-0">Porting to 2.0</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#extending-embedding-changes">Extending/Embedding Changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#distutils-making-modules-easy-to-install">Distutils: Making Modules Easy to Install</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#xml-modules">XML Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#module-changes">Module changes</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#new-modules">New modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#idle-improvements">IDLE Improvements</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#deleted-and-deprecated-modules">Deleted and Deprecated Modules</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="2.0.html#acknowledgements">Acknowledgements</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p>The “Changelog” is an HTML version of the <a class="reference external" href="https://pypi.org/project/blurb">file built</a> from the contents of the
|
||||
<a class="reference external" href="https://github.com/python/cpython/tree/3.7/Misc/NEWS.d">Misc/NEWS.d</a> directory tree, which contains <em>all</em> nontrivial changes
|
||||
to Python for the current version.</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Changelog</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-next">Python next</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-4-final">Python 3.7.4 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-4-release-candidate-2">Python 3.7.4 release candidate 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-4-release-candidate-1">Python 3.7.4 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-3-final">Python 3.7.3 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-3-release-candidate-1">Python 3.7.3 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-2-final">Python 3.7.2 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-2-release-candidate-1">Python 3.7.2 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-1-final">Python 3.7.1 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-1-release-candidate-2">Python 3.7.1 release candidate 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-1-release-candidate-1">Python 3.7.1 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-final">Python 3.7.0 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-release-candidate-1">Python 3.7.0 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-beta-5">Python 3.7.0 beta 5</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-beta-4">Python 3.7.0 beta 4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-beta-3">Python 3.7.0 beta 3</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-beta-2">Python 3.7.0 beta 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-beta-1">Python 3.7.0 beta 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-alpha-4">Python 3.7.0 alpha 4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-alpha-3">Python 3.7.0 alpha 3</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-alpha-2">Python 3.7.0 alpha 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-7-0-alpha-1">Python 3.7.0 alpha 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-6-final">Python 3.6.6 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-6-release-candidate-1">Python 3.6.6 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-5-final">Python 3.6.5 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-5-release-candidate-1">Python 3.6.5 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-4-final">Python 3.6.4 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-4-release-candidate-1">Python 3.6.4 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-3-final">Python 3.6.3 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-3-release-candidate-1">Python 3.6.3 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-2-final">Python 3.6.2 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-2-release-candidate-2">Python 3.6.2 release candidate 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-2-release-candidate-1">Python 3.6.2 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-1-final">Python 3.6.1 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-1-release-candidate-1">Python 3.6.1 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-final">Python 3.6.0 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-release-candidate-2">Python 3.6.0 release candidate 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-release-candidate-1">Python 3.6.0 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-beta-4">Python 3.6.0 beta 4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-beta-3">Python 3.6.0 beta 3</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-beta-2">Python 3.6.0 beta 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-beta-1">Python 3.6.0 beta 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-alpha-4">Python 3.6.0 alpha 4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-alpha-3">Python 3.6.0 alpha 3</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-alpha-2">Python 3.6.0 alpha 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-6-0-alpha-1">Python 3.6.0 alpha 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-5-final">Python 3.5.5 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-5-release-candidate-1">Python 3.5.5 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-4-final">Python 3.5.4 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-4-release-candidate-1">Python 3.5.4 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-3-final">Python 3.5.3 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-3-release-candidate-1">Python 3.5.3 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-2-final">Python 3.5.2 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-2-release-candidate-1">Python 3.5.2 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-1-final">Python 3.5.1 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-1-release-candidate-1">Python 3.5.1 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-final">Python 3.5.0 final</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-release-candidate-4">Python 3.5.0 release candidate 4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-release-candidate-3">Python 3.5.0 release candidate 3</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-release-candidate-2">Python 3.5.0 release candidate 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-release-candidate-1">Python 3.5.0 release candidate 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-beta-4">Python 3.5.0 beta 4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-beta-3">Python 3.5.0 beta 3</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-beta-2">Python 3.5.0 beta 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-beta-1">Python 3.5.0 beta 1</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-alpha-4">Python 3.5.0 alpha 4</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-alpha-3">Python 3.5.0 alpha 3</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-alpha-2">Python 3.5.0 alpha 2</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="changelog.html#python-3-5-0-alpha-1">Python 3.5.0 alpha 1</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</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="../contents.html"
|
||||
title="previous chapter">Python Documentation contents</a></p>
|
||||
<h4>Next topic</h4>
|
||||
<p class="topless"><a href="3.7.html"
|
||||
title="next chapter">What’s New In Python 3.7</a></p>
|
||||
<div role="note" aria-label="source link">
|
||||
<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/3.7/Doc/whatsnew/index.rst"
|
||||
rel="nofollow">Show Source
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</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="3.7.html" title="What’s New In Python 3.7"
|
||||
>next</a> |</li>
|
||||
<li class="right" >
|
||||
<a href="../contents.html" title="Python Documentation contents"
|
||||
>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>
|
||||
<span class="language_switcher_placeholder">en</span>
|
||||
<span class="version_switcher_placeholder">3.7.4</span>
|
||||
<a href="../index.html">Documentation </a> »
|
||||
</li>
|
||||
|
||||
<li class="right">
|
||||
|
||||
|
||||
<div class="inline-search" style="display: none" role="search">
|
||||
<form class="inline-search" action="../search.html" method="get">
|
||||
<input placeholder="Quick search" type="text" name="q" />
|
||||
<input type="submit" value="Go" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">$('.inline-search').show(0);</script>
|
||||
|
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer">
|
||||
© <a href="../copyright.html">Copyright</a> 2001-2019, 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 Jul 13, 2019.
|
||||
<a href="../bugs.html">Found a bug</a>?
|
||||
<br />
|
||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user