gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

850 lines
73KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="What’s New In Python 3.1" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.1.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Author, Raymond Hettinger,. This article explains the new features in Python 3.1, compared to 3.0. Python 3.1 was released on June 27, 2009. PEP 372: Ordered Dictionaries: Regular Python dictionari..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Author, Raymond Hettinger,. This article explains the new features in Python 3.1, compared to 3.0. Python 3.1 was released on June 27, 2009. PEP 372: Ordered Dictionaries: Regular Python dictionari..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>What’s New In Python 3.1 &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="What’s New In Python 3.0" href="3.0.html" />
  33. <link rel="prev" title="What’s New In Python 3.2" href="3.2.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.1.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#">What’s New In Python 3.1</a><ul>
  86. <li><a class="reference internal" href="#pep-372-ordered-dictionaries">PEP 372: Ordered Dictionaries</a></li>
  87. <li><a class="reference internal" href="#pep-378-format-specifier-for-thousands-separator">PEP 378: Format Specifier for Thousands Separator</a></li>
  88. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  89. <li><a class="reference internal" href="#new-improved-and-deprecated-modules">New, Improved, and Deprecated Modules</a></li>
  90. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  91. <li><a class="reference internal" href="#idle">IDLE</a></li>
  92. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  93. <li><a class="reference internal" href="#porting-to-python-3-1">Porting to Python 3.1</a></li>
  94. </ul>
  95. </li>
  96. </ul>
  97. </div>
  98. <div>
  99. <h4>Previous topic</h4>
  100. <p class="topless"><a href="3.2.html"
  101. title="previous chapter">What’s New In Python 3.2</a></p>
  102. </div>
  103. <div>
  104. <h4>Next topic</h4>
  105. <p class="topless"><a href="3.0.html"
  106. title="next chapter">What’s New In Python 3.0</a></p>
  107. </div>
  108. <div role="note" aria-label="source link">
  109. <h3>This Page</h3>
  110. <ul class="this-page-menu">
  111. <li><a href="../bugs.html">Report a Bug</a></li>
  112. <li>
  113. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.1.rst"
  114. rel="nofollow">Show Source
  115. </a>
  116. </li>
  117. </ul>
  118. </div>
  119. </nav>
  120. </div>
  121. </div>
  122. <div class="related" role="navigation" aria-label="related navigation">
  123. <h3>Navigation</h3>
  124. <ul>
  125. <li class="right" style="margin-right: 10px">
  126. <a href="../genindex.html" title="General Index"
  127. accesskey="I">index</a></li>
  128. <li class="right" >
  129. <a href="../py-modindex.html" title="Python Module Index"
  130. >modules</a> |</li>
  131. <li class="right" >
  132. <a href="3.0.html" title="What’s New In Python 3.0"
  133. accesskey="N">next</a> |</li>
  134. <li class="right" >
  135. <a href="3.2.html" title="What’s New In Python 3.2"
  136. accesskey="P">previous</a> |</li>
  137. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  138. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  139. <li class="switchers">
  140. <div class="language_switcher_placeholder"></div>
  141. <div class="version_switcher_placeholder"></div>
  142. </li>
  143. <li>
  144. </li>
  145. <li id="cpython-language-and-version">
  146. <a href="../index.html">3.12.3 Documentation</a> &#187;
  147. </li>
  148. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  149. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.1</a></li>
  150. <li class="right">
  151. <div class="inline-search" role="search">
  152. <form class="inline-search" action="../search.html" method="get">
  153. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  154. <input type="submit" value="Go" />
  155. </form>
  156. </div>
  157. |
  158. </li>
  159. <li class="right">
  160. <label class="theme-selector-label">
  161. Theme
  162. <select class="theme-selector" oninput="activateTheme(this.value)">
  163. <option value="auto" selected>Auto</option>
  164. <option value="light">Light</option>
  165. <option value="dark">Dark</option>
  166. </select>
  167. </label> |</li>
  168. </ul>
  169. </div>
  170. <div class="document">
  171. <div class="documentwrapper">
  172. <div class="bodywrapper">
  173. <div class="body" role="main">
  174. <section id="what-s-new-in-python-3-1">
  175. <h1>What’s New In Python 3.1<a class="headerlink" href="#what-s-new-in-python-3-1" title="Link to this heading">¶</a></h1>
  176. <dl class="field-list simple">
  177. <dt class="field-odd">Author<span class="colon">:</span></dt>
  178. <dd class="field-odd"><p>Raymond Hettinger</p>
  179. </dd>
  180. </dl>
  181. <p>This article explains the new features in Python 3.1, compared to 3.0.
  182. Python 3.1 was released on June 27, 2009.</p>
  183. <section id="pep-372-ordered-dictionaries">
  184. <h2>PEP 372: Ordered Dictionaries<a class="headerlink" href="#pep-372-ordered-dictionaries" title="Link to this heading">¶</a></h2>
  185. <p>Regular Python dictionaries iterate over key/value pairs in arbitrary order.
  186. Over the years, a number of authors have written alternative implementations
  187. that remember the order that the keys were originally inserted. Based on
  188. the experiences from those implementations, a new
  189. <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>
  190. <p>The OrderedDict API is substantially the same as regular dictionaries
  191. but will iterate over keys and values in a guaranteed order depending on
  192. when a key was first inserted. If a new entry overwrites an existing entry,
  193. the original insertion position is left unchanged. Deleting an entry and
  194. reinserting it will move it to the end.</p>
  195. <p>The standard library now supports use of ordered dictionaries in several
  196. 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
  197. configuration files be read, modified, and then written back in their original
  198. 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
  199. returns an ordered dictionary with the values appearing in the same order as
  200. 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
  201. an <em>object_pairs_hook</em> to allow OrderedDicts to be built by the decoder.
  202. Support was also added for third-party tools like <a class="reference external" href="https://pyyaml.org/">PyYAML</a>.</p>
  203. <div class="admonition seealso">
  204. <p class="admonition-title">See also</p>
  205. <dl class="simple">
  206. <dt><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0372/"><strong>PEP 372</strong></a> - Ordered Dictionaries</dt><dd><p>PEP written by Armin Ronacher and Raymond Hettinger. Implementation
  207. written by Raymond Hettinger.</p>
  208. </dd>
  209. </dl>
  210. </div>
  211. <p>Since an ordered dictionary remembers its insertion order, it can be used
  212. in conjunction with sorting to make a sorted dictionary:</p>
  213. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># regular unsorted dictionary</span>
  214. <span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;banana&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;apple&#39;</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span> <span class="s1">&#39;pear&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;orange&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">}</span>
  215. <span class="gp">&gt;&gt;&gt; </span><span class="c1"># dictionary sorted by key</span>
  216. <span class="gp">&gt;&gt;&gt; </span><span class="n">OrderedDict</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">t</span><span class="p">:</span> <span class="n">t</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
  217. <span class="go">OrderedDict([(&#39;apple&#39;, 4), (&#39;banana&#39;, 3), (&#39;orange&#39;, 2), (&#39;pear&#39;, 1)])</span>
  218. <span class="gp">&gt;&gt;&gt; </span><span class="c1"># dictionary sorted by value</span>
  219. <span class="gp">&gt;&gt;&gt; </span><span class="n">OrderedDict</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">t</span><span class="p">:</span> <span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
  220. <span class="go">OrderedDict([(&#39;pear&#39;, 1), (&#39;orange&#39;, 2), (&#39;banana&#39;, 3), (&#39;apple&#39;, 4)])</span>
  221. <span class="gp">&gt;&gt;&gt; </span><span class="c1"># dictionary sorted by length of the key string</span>
  222. <span class="gp">&gt;&gt;&gt; </span><span class="n">OrderedDict</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">t</span><span class="p">:</span> <span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="mi">0</span><span class="p">])))</span>
  223. <span class="go">OrderedDict([(&#39;pear&#39;, 1), (&#39;apple&#39;, 4), (&#39;orange&#39;, 2), (&#39;banana&#39;, 3)])</span>
  224. </pre></div>
  225. </div>
  226. <p>The new sorted dictionaries maintain their sort order when entries
  227. are deleted. But when new keys are added, the keys are appended
  228. to the end and the sort is not maintained.</p>
  229. </section>
  230. <section id="pep-378-format-specifier-for-thousands-separator">
  231. <h2>PEP 378: Format Specifier for Thousands Separator<a class="headerlink" href="#pep-378-format-specifier-for-thousands-separator" title="Link to this heading">¶</a></h2>
  232. <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
  233. a mini-language that now includes a simple, non-locale aware way to format
  234. a number with a thousands separator. That provides a way to humanize a
  235. program’s output, improving its professional appearance and readability:</p>
  236. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">format</span><span class="p">(</span><span class="mi">1234567</span><span class="p">,</span> <span class="s1">&#39;,d&#39;</span><span class="p">)</span>
  237. <span class="go">&#39;1,234,567&#39;</span>
  238. <span class="gp">&gt;&gt;&gt; </span><span class="nb">format</span><span class="p">(</span><span class="mf">1234567.89</span><span class="p">,</span> <span class="s1">&#39;,.2f&#39;</span><span class="p">)</span>
  239. <span class="go">&#39;1,234,567.89&#39;</span>
  240. <span class="gp">&gt;&gt;&gt; </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">&#39;,f&#39;</span><span class="p">)</span>
  241. <span class="go">&#39;12,345.600000+8,901,234.120000j&#39;</span>
  242. <span class="gp">&gt;&gt;&gt; </span><span class="nb">format</span><span class="p">(</span><span class="n">Decimal</span><span class="p">(</span><span class="s1">&#39;1234567.89&#39;</span><span class="p">),</span> <span class="s1">&#39;,f&#39;</span><span class="p">)</span>
  243. <span class="go">&#39;1,234,567.89&#39;</span>
  244. </pre></div>
  245. </div>
  246. <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>
  247. 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>
  248. <p>Discussions are underway about how to specify alternative separators
  249. like dots, spaces, apostrophes, or underscores. Locale-aware applications
  250. should use the existing <em>n</em> format specifier which already has some support
  251. for thousands separators.</p>
  252. <div class="admonition seealso">
  253. <p class="admonition-title">See also</p>
  254. <dl class="simple">
  255. <dt><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/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
  256. Mark Dickinson.</p>
  257. </dd>
  258. </dl>
  259. </div>
  260. </section>
  261. <section id="other-language-changes">
  262. <h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
  263. <p>Some smaller changes made to the core Python language are:</p>
  264. <ul>
  265. <li><p>Directories and zip archives containing a <code class="file docutils literal notranslate"><span class="pre">__main__.py</span></code>
  266. file can now be executed directly by passing their name to the
  267. interpreter. The directory/zipfile is automatically inserted as the
  268. first entry in sys.path. (Suggestion and initial patch by Andy Chu;
  269. revised patch by Phillip J. Eby and Nick Coghlan; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1739468">bpo-1739468</a>.)</p></li>
  270. <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
  271. number of bits necessary to represent its argument in binary:</p>
  272. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="mi">37</span>
  273. <span class="gp">&gt;&gt;&gt; </span><span class="nb">bin</span><span class="p">(</span><span class="mi">37</span><span class="p">)</span>
  274. <span class="go">&#39;0b100101&#39;</span>
  275. <span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="o">.</span><span class="n">bit_length</span><span class="p">()</span>
  276. <span class="go">6</span>
  277. <span class="gp">&gt;&gt;&gt; </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>
  278. <span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="o">.</span><span class="n">bit_length</span><span class="p">()</span>
  279. <span class="go">123</span>
  280. <span class="gp">&gt;&gt;&gt; </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>
  281. <span class="go">124</span>
  282. </pre></div>
  283. </div>
  284. <p>(Contributed by Fredrik Johansson, Victor Stinner, Raymond Hettinger,
  285. and Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=3439">bpo-3439</a>.)</p>
  286. </li>
  287. <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
  288. numbered:</p>
  289. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;Sir </span><span class="si">{}</span><span class="s1"> of </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Gallahad&#39;</span><span class="p">,</span> <span class="s1">&#39;Camelot&#39;</span><span class="p">)</span>
  290. <span class="go">&#39;Sir Gallahad of Camelot&#39;</span>
  291. </pre></div>
  292. </div>
  293. <p>Formerly, the string would have required numbered fields such as:
  294. <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>
  295. <p>(Contributed by Eric Smith; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5237">bpo-5237</a>.)</p>
  296. </li>
  297. <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
  298. 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>.
  299. This change solves the confusion around which types were supported by the
  300. <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
  301. <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>
  302. methods with intermediate translation tables of the appropriate type.</p>
  303. <p>(Contributed by Georg Brandl; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5675">bpo-5675</a>.)</p>
  304. </li>
  305. <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
  306. managers in a single statement:</p>
  307. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s1">&#39;mylog.txt&#39;</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">&#39;a.out&#39;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">outfile</span><span class="p">:</span>
  308. <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>
  309. <span class="gp">... </span> <span class="k">if</span> <span class="s1">&#39;&lt;critical&gt;&#39;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
  310. <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>
  311. </pre></div>
  312. </div>
  313. <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
  314. needed and is now deprecated.</p>
  315. <p>(Contributed by Georg Brandl and Mattias Brändström;
  316. <a class="reference external" href="https://codereview.appspot.com/53094">appspot issue 53094</a>.)</p>
  317. </li>
  318. <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.
  319. Previously it returned a float:</p>
  320. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </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>
  321. <span class="go">1100</span>
  322. </pre></div>
  323. </div>
  324. <p>(Contributed by Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4707">bpo-4707</a>.)</p>
  325. </li>
  326. <li><p>Python now uses David Gay’s algorithm for finding the shortest floating
  327. point representation that doesn’t change its value. This should help
  328. mitigate some of the confusion surrounding binary floating point
  329. numbers.</p>
  330. <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
  331. have an exact equivalent in binary floating point. Since there is no exact
  332. equivalent, an expression like <code class="docutils literal notranslate"><span class="pre">float('1.1')</span></code> evaluates to the nearest
  333. representable value which is <code class="docutils literal notranslate"><span class="pre">0x1.199999999999ap+0</span></code> in hex or
  334. <code class="docutils literal notranslate"><span class="pre">1.100000000000000088817841970012523233890533447265625</span></code> in decimal. That
  335. nearest value was and still is used in subsequent floating point
  336. calculations.</p>
  337. <p>What is new is how the number gets displayed. Formerly, Python used a
  338. 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>
  339. <span class="pre">'.17g')</span></code> which evaluated to <code class="docutils literal notranslate"><span class="pre">'1.1000000000000001'</span></code>. The advantage of
  340. using 17 digits was that it relied on IEEE-754 guarantees to assure that
  341. <code class="docutils literal notranslate"><span class="pre">eval(repr(1.1))</span></code> would round-trip exactly to its original value. The
  342. disadvantage is that many people found the output to be confusing (mistaking
  343. intrinsic limitations of binary floating point representation as being a
  344. problem with Python itself).</p>
  345. <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>.
  346. Effectively, it searches all equivalent string representations (ones that
  347. get stored with the same underlying float value) and returns the shortest
  348. representation.</p>
  349. <p>The new algorithm tends to emit cleaner representations when possible, but
  350. it does not change the underlying values. So, it is still the case that
  351. <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>
  352. <p>The new algorithm depends on certain features in the underlying floating
  353. point implementation. If the required features are not found, the old
  354. algorithm will continue to be used. Also, the text pickle protocols
  355. assure cross-platform portability by using the old algorithm.</p>
  356. <p>(Contributed by Eric Smith and Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1580">bpo-1580</a>)</p>
  357. </li>
  358. </ul>
  359. </section>
  360. <section id="new-improved-and-deprecated-modules">
  361. <h2>New, Improved, and Deprecated Modules<a class="headerlink" href="#new-improved-and-deprecated-modules" title="Link to this heading">¶</a></h2>
  362. <ul>
  363. <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
  364. counting of unique items in a sequence or iterable:</p>
  365. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Counter</span><span class="p">([</span><span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="s1">&#39;blue&#39;</span><span class="p">,</span> <span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="s1">&#39;green&#39;</span><span class="p">,</span> <span class="s1">&#39;blue&#39;</span><span class="p">,</span> <span class="s1">&#39;blue&#39;</span><span class="p">])</span>
  366. <span class="go">Counter({&#39;blue&#39;: 3, &#39;red&#39;: 2, &#39;green&#39;: 1})</span>
  367. </pre></div>
  368. </div>
  369. <p>(Contributed by Raymond Hettinger; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1696199">bpo-1696199</a>.)</p>
  370. </li>
  371. <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.
  372. The basic idea of ttk is to separate, to the extent possible, the code
  373. implementing a widget’s behavior from the code implementing its appearance.</p>
  374. <p>(Contributed by Guilherme Polo; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2983">bpo-2983</a>.)</p>
  375. </li>
  376. <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
  377. the context management protocol:</p>
  378. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># Automatically close file after writing</span>
  379. <span class="gp">&gt;&gt;&gt; </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">&quot;wb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
  380. <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">&quot;xxx&quot;</span><span class="p">)</span>
  381. </pre></div>
  382. </div>
  383. <p>(Contributed by Antoine Pitrou.)</p>
  384. </li>
  385. <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
  386. 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
  387. exact but can sometimes be surprising:</p>
  388. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </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>
  389. <span class="go">Decimal(&#39;1.100000000000000088817841970012523233890533447265625&#39;)</span>
  390. </pre></div>
  391. </div>
  392. <p>The long decimal result shows the actual binary fraction being
  393. stored for <em>1.1</em>. The fraction has many digits because <em>1.1</em> cannot
  394. be exactly represented in binary.</p>
  395. <p>(Contributed by Raymond Hettinger and Mark Dickinson.)</p>
  396. </li>
  397. <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
  398. <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
  399. four for generating combinatorics including permutations and Cartesian
  400. 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
  401. 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
  402. an optional <em>step</em> argument and can accept any type of counting
  403. 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
  404. <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>
  405. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </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">&#39;LOVE&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)]</span>
  406. <span class="go">[&#39;LL&#39;, &#39;LO&#39;, &#39;LV&#39;, &#39;LE&#39;, &#39;OO&#39;, &#39;OV&#39;, &#39;OE&#39;, &#39;VV&#39;, &#39;VE&#39;, &#39;EE&#39;]</span>
  407. <span class="gp">&gt;&gt;&gt; </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>
  408. <span class="go">[2, 3, 5, 7]</span>
  409. <span class="gp">&gt;&gt;&gt; </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>
  410. <span class="gp">&gt;&gt;&gt; </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>
  411. <span class="go">[Fraction(1, 2), Fraction(2, 3), Fraction(5, 6), Fraction(1, 1)]</span>
  412. </pre></div>
  413. </div>
  414. <p>(Contributed by Raymond Hettinger.)</p>
  415. </li>
  416. <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
  417. <em>rename</em> which lets invalid fieldnames be automatically converted to
  418. positional names in the form _0, _1, etc. This is useful when
  419. the field names are being created by an external source such as a
  420. CSV header, SQL field list, or user input:</p>
  421. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">query</span> <span class="o">=</span> <span class="nb">input</span><span class="p">()</span>
  422. <span class="go">SELECT region, dept, count(*) FROM main GROUPBY region, dept</span>
  423. <span class="gp">&gt;&gt;&gt; </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>
  424. <span class="gp">&gt;&gt;&gt; </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>
  425. <span class="gp">&gt;&gt;&gt; </span><span class="n">UserQuery</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s1">&#39;UserQuery&#39;</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>
  426. <span class="gp">&gt;&gt;&gt; </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>
  427. <span class="go">[UserQuery(region=&#39;South&#39;, dept=&#39;Shipping&#39;, _2=185),</span>
  428. <span class="go"> UserQuery(region=&#39;North&#39;, dept=&#39;Accounting&#39;, _2=37),</span>
  429. <span class="go"> UserQuery(region=&#39;West&#39;, dept=&#39;Sales&#39;, _2=419)]</span>
  430. </pre></div>
  431. </div>
  432. <p>(Contributed by Raymond Hettinger; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1818">bpo-1818</a>.)</p>
  433. </li>
  434. <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
  435. accept a flags parameter.</p>
  436. <p>(Contributed by Gregory Smith.)</p>
  437. </li>
  438. <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>
  439. class for applications that are not using logging but are calling
  440. library code that does. Setting-up a null handler will suppress
  441. spurious warnings such as “No handlers could be found for logger foo”:</p>
  442. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </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>
  443. <span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s2">&quot;foo&quot;</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>
  444. </pre></div>
  445. </div>
  446. <p>(Contributed by Vinay Sajip; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4384">bpo-4384</a>).</p>
  447. </li>
  448. <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
  449. now supports the execution of packages by looking for and executing
  450. a <code class="docutils literal notranslate"><span class="pre">__main__</span></code> submodule when a package name is supplied.</p>
  451. <p>(Contributed by Andi Vajda; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4195">bpo-4195</a>.)</p>
  452. </li>
  453. <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
  454. <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://peps.python.org/pep-0302/"><strong>PEP 302</strong></a> loader).</p>
  455. <p>(Contributed by Alexander Belopolsky; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4201">bpo-4201</a>.)</p>
  456. </li>
  457. <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>
  458. </ul>
  459. <blockquote>
  460. <div><p>(Suggested by Antoine Pitrou and Jesse Noller. Implemented by
  461. Jack Diederich; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5228">bpo-5228</a>.)</p>
  462. </div></blockquote>
  463. <ul>
  464. <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('&#64;')</span></code>
  465. works as expected in the interactive environment.</p>
  466. <p>(Contributed by David Laban; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4739">bpo-4739</a>.)</p>
  467. </li>
  468. <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
  469. of tests. And it supports marking a test as an expected failure, a test that
  470. is known to be broken, but shouldn’t be counted as a failure on a
  471. TestResult:</p>
  472. <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>
  473. <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">&quot;win&quot;</span><span class="p">),</span> <span class="s2">&quot;requires Windows&quot;</span><span class="p">)</span>
  474. <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>
  475. <span class="o">...</span>
  476. <span class="nd">@unittest</span><span class="o">.</span><span class="n">expectedFailure</span>
  477. <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>
  478. <span class="o">...</span>
  479. </pre></div>
  480. </div>
  481. <p>Also, tests for exceptions have been builtout to work with context managers
  482. 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>
  483. <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>
  484. <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>
  485. <span class="n">x</span> <span class="o">/</span> <span class="mi">0</span>
  486. </pre></div>
  487. </div>
  488. <p>In addition, several new assertion methods were added including
  489. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertSetEqual" title="unittest.TestCase.assertSetEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertSetEqual()</span></code></a>,
  490. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertDictEqual" title="unittest.TestCase.assertDictEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertDictEqual()</span></code></a>,
  491. <code class="xref py py-meth docutils literal notranslate"><span class="pre">assertDictContainsSubset()</span></code>,
  492. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertListEqual" title="unittest.TestCase.assertListEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertListEqual()</span></code></a>,
  493. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertTupleEqual" title="unittest.TestCase.assertTupleEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertTupleEqual()</span></code></a>,
  494. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertSequenceEqual" title="unittest.TestCase.assertSequenceEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertSequenceEqual()</span></code></a>,
  495. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRaisesRegex" title="unittest.TestCase.assertRaisesRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRaisesRegexp()</span></code></a>,
  496. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertIsNone" title="unittest.TestCase.assertIsNone"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertIsNone()</span></code></a>,
  497. and <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertIsNotNone" title="unittest.TestCase.assertIsNotNone"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertIsNotNone()</span></code></a>.</p>
  498. <p>(Contributed by Benjamin Peterson and Antoine Pitrou.)</p>
  499. </li>
  500. <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 <a class="reference internal" href="../library/io.html#io.IOBase.seek" title="io.IOBase.seek"><code class="xref py py-meth docutils literal notranslate"><span class="pre">seek()</span></code></a>
  501. method: <a class="reference internal" href="../library/os.html#os.SEEK_SET" title="os.SEEK_SET"><code class="xref py py-data docutils literal notranslate"><span class="pre">SEEK_SET</span></code></a>, <a class="reference internal" href="../library/os.html#os.SEEK_CUR" title="os.SEEK_CUR"><code class="xref py py-data docutils literal notranslate"><span class="pre">SEEK_CUR</span></code></a>, and <a class="reference internal" href="../library/os.html#os.SEEK_END" title="os.SEEK_END"><code class="xref py py-data docutils literal notranslate"><span class="pre">SEEK_END</span></code></a>.</p></li>
  502. <li><p>The <a class="reference internal" href="../library/sys.html#sys.version_info" title="sys.version_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.version_info</span></code></a> tuple is now a named tuple:</p>
  503. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">version_info</span>
  504. <span class="go">sys.version_info(major=3, minor=1, micro=0, releaselevel=&#39;alpha&#39;, serial=2)</span>
  505. </pre></div>
  506. </div>
  507. <p>(Contributed by Ross Light; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4285">bpo-4285</a>.)</p>
  508. </li>
  509. <li><p>The <a class="reference internal" href="../library/nntplib.html#module-nntplib" title="nntplib: NNTP protocol client (requires sockets). (deprecated)"><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>
  510. <p>(Contributed by Derek Morr; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1655">bpo-1655</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1664">bpo-1664</a>.)</p>
  511. </li>
  512. <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
  513. Python 2.x when used with protocol 2 or lower. The reorganization of the
  514. standard library changed the formal reference for many objects. For
  515. 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
  516. 3. This change confounded efforts to share data between different versions of
  517. Python. But now when protocol 2 or lower is selected, the pickler will
  518. automatically use the old Python 2 names for both loading and dumping. This
  519. remapping is turned-on by default but can be disabled with the <em>fix_imports</em>
  520. option:</p>
  521. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </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>
  522. <span class="gp">&gt;&gt;&gt; </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>
  523. <span class="go">b&#39;c__builtin__\nset\np0\n((lp1\nL1L\naL2L\naL3L\natp2\nRp3\n.&#39;</span>
  524. <span class="gp">&gt;&gt;&gt; </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>
  525. <span class="go">b&#39;cbuiltins\nset\np0\n((lp1\nL1L\naL2L\naL3L\natp2\nRp3\n.&#39;</span>
  526. </pre></div>
  527. </div>
  528. <p>An unfortunate but unavoidable side-effect of this change is that protocol 2
  529. pickles produced by Python 3.1 won’t be readable with Python 3.0. The latest
  530. pickle protocol, protocol 3, should be used when migrating data between
  531. Python 3.x implementations, as it doesn’t attempt to remain compatible with
  532. Python 2.x.</p>
  533. <p>(Contributed by Alexandre Vassalotti and Antoine Pitrou, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6137">bpo-6137</a>.)</p>
  534. </li>
  535. <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,
  536. 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
  537. 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
  538. step forward in documenting and defining the actions that take place during
  539. imports.</p>
  540. <p>(Contributed by Brett Cannon.)</p>
  541. </li>
  542. </ul>
  543. </section>
  544. <section id="optimizations">
  545. <h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
  546. <p>Major performance enhancements have been added:</p>
  547. <ul>
  548. <li><p>The new I/O library (as defined in <span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-3116/"><strong>PEP 3116</strong></a>) was mostly written in
  549. Python and quickly proved to be a problematic bottleneck in Python 3.0.
  550. In Python 3.1, the I/O library has been entirely rewritten in C and is
  551. 2 to 20 times faster depending on the task at hand. The pure Python
  552. version is still available for experimentation purposes through
  553. the <code class="docutils literal notranslate"><span class="pre">_pyio</span></code> module.</p>
  554. <p>(Contributed by Amaury Forgeot d’Arc and Antoine Pitrou.)</p>
  555. </li>
  556. <li><p>Added a heuristic so that tuples and dicts containing only untrackable objects
  557. are not tracked by the garbage collector. This can reduce the size of
  558. collections and therefore the garbage collection overhead on long-running
  559. programs, depending on their particular use of datatypes.</p>
  560. <p>(Contributed by Antoine Pitrou, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4688">bpo-4688</a>.)</p>
  561. </li>
  562. <li><p>Enabling a configure option named <code class="docutils literal notranslate"><span class="pre">--with-computed-gotos</span></code>
  563. on compilers that support it (notably: gcc, SunPro, icc), the bytecode
  564. evaluation loop is compiled with a new dispatch mechanism which gives
  565. speedups of up to 20%, depending on the system, the compiler, and
  566. the benchmark.</p>
  567. <p>(Contributed by Antoine Pitrou along with a number of other participants,
  568. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4753">bpo-4753</a>).</p>
  569. </li>
  570. <li><p>The decoding of UTF-8, UTF-16 and LATIN-1 is now two to four times
  571. faster.</p>
  572. <p>(Contributed by Antoine Pitrou and Amaury Forgeot d’Arc, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4868">bpo-4868</a>.)</p>
  573. </li>
  574. <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
  575. its performance. In addition, the API was modified so that json works
  576. 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
  577. module closely match the <a class="reference external" href="https://json.org/">JSON specification</a>
  578. which is defined in terms of Unicode.</p>
  579. <p>(Contributed by Bob Ippolito and converted to Py3.1 by Antoine Pitrou
  580. and Benjamin Peterson; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4136">bpo-4136</a>.)</p>
  581. </li>
  582. <li><p>Unpickling now interns the attribute names of pickled objects. This saves
  583. memory and allows pickles to be smaller.</p>
  584. <p>(Contributed by Jake McGuire and Antoine Pitrou; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5084">bpo-5084</a>.)</p>
  585. </li>
  586. </ul>
  587. </section>
  588. <section id="idle">
  589. <h2>IDLE<a class="headerlink" href="#idle" title="Link to this heading">¶</a></h2>
  590. <ul>
  591. <li><p>IDLE’s format menu now provides an option to strip trailing whitespace
  592. from a source file.</p>
  593. <p>(Contributed by Roger D. Serwy; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5150">bpo-5150</a>.)</p>
  594. </li>
  595. </ul>
  596. </section>
  597. <section id="build-and-c-api-changes">
  598. <h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Link to this heading">¶</a></h2>
  599. <p>Changes to Python’s build process and to the C API include:</p>
  600. <ul>
  601. <li><p>Integers are now stored internally either in base <code class="docutils literal notranslate"><span class="pre">2**15</span></code> or in base
  602. <code class="docutils literal notranslate"><span class="pre">2**30</span></code>, the base being determined at build time. Previously, they
  603. were always stored in base <code class="docutils literal notranslate"><span class="pre">2**15</span></code>. Using base <code class="docutils literal notranslate"><span class="pre">2**30</span></code> gives
  604. significant performance improvements on 64-bit machines, but
  605. benchmark results on 32-bit machines have been mixed. Therefore,
  606. the default is to use base <code class="docutils literal notranslate"><span class="pre">2**30</span></code> on 64-bit machines and base <code class="docutils literal notranslate"><span class="pre">2**15</span></code>
  607. on 32-bit machines; on Unix, there’s a new configure option
  608. <code class="docutils literal notranslate"><span class="pre">--enable-big-digits</span></code> that can be used to override this default.</p>
  609. <p>Apart from the performance improvements this change should be invisible to
  610. end users, with one exception: for testing and debugging purposes there’s a
  611. new <a class="reference internal" href="../library/sys.html#sys.int_info" title="sys.int_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.int_info</span></code></a> that provides information about the
  612. internal format, giving the number of bits per digit and the size in bytes
  613. of the C type used to store each digit:</p>
  614. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">sys</span>
  615. <span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">int_info</span>
  616. <span class="go">sys.int_info(bits_per_digit=30, sizeof_digit=4)</span>
  617. </pre></div>
  618. </div>
  619. <p>(Contributed by Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4258">bpo-4258</a>.)</p>
  620. </li>
  621. <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
  622. <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>
  623. <p>(Contributed by Mark Dickinson and Lisandro Dalcrin; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5175">bpo-5175</a>.)</p>
  624. </li>
  625. <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>
  626. <p>(Contributed by Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4910">bpo-4910</a>.)</p>
  627. </li>
  628. <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
  629. 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>
  630. <p>(Contributed by Mark Dickinson; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5914">bpo-5914</a>.)</p>
  631. </li>
  632. <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.
  633. The principal difference is that the new type has a well defined interface
  634. for passing typing safety information and a less complicated signature
  635. for calling a destructor. The old type had a problematic API and is now
  636. deprecated.</p>
  637. <p>(Contributed by Larry Hastings; <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5630">bpo-5630</a>.)</p>
  638. </li>
  639. </ul>
  640. </section>
  641. <section id="porting-to-python-3-1">
  642. <h2>Porting to Python 3.1<a class="headerlink" href="#porting-to-python-3-1" title="Link to this heading">¶</a></h2>
  643. <p>This section lists previously described changes and other bugfixes
  644. that may require changes to your code:</p>
  645. <ul>
  646. <li><p>The new floating point string representations can break existing doctests.
  647. For example:</p>
  648. <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>
  649. <span class="w"> </span><span class="sd">&#39;&#39;&#39;Compute the base of natural logarithms.</span>
  650. <span class="sd"> &gt;&gt;&gt; e()</span>
  651. <span class="sd"> 2.7182818284590451</span>
  652. <span class="sd"> &#39;&#39;&#39;</span>
  653. <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>
  654. <span class="n">doctest</span><span class="o">.</span><span class="n">testmod</span><span class="p">()</span>
  655. <span class="o">**********************************************************************</span>
  656. <span class="n">Failed</span> <span class="n">example</span><span class="p">:</span>
  657. <span class="n">e</span><span class="p">()</span>
  658. <span class="n">Expected</span><span class="p">:</span>
  659. <span class="mf">2.7182818284590451</span>
  660. <span class="n">Got</span><span class="p">:</span>
  661. <span class="mf">2.718281828459045</span>
  662. <span class="o">**********************************************************************</span>
  663. </pre></div>
  664. </div>
  665. </li>
  666. <li><p>The automatic name remapping in the pickle module for protocol 2 or lower can
  667. make Python 3.1 pickles unreadable in Python 3.0. One solution is to use
  668. 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>.
  669. See the discussion above for more details.</p></li>
  670. </ul>
  671. </section>
  672. </section>
  673. <div class="clearer"></div>
  674. </div>
  675. </div>
  676. </div>
  677. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  678. <div class="sphinxsidebarwrapper">
  679. <div>
  680. <h3><a href="../contents.html">Table of Contents</a></h3>
  681. <ul>
  682. <li><a class="reference internal" href="#">What’s New In Python 3.1</a><ul>
  683. <li><a class="reference internal" href="#pep-372-ordered-dictionaries">PEP 372: Ordered Dictionaries</a></li>
  684. <li><a class="reference internal" href="#pep-378-format-specifier-for-thousands-separator">PEP 378: Format Specifier for Thousands Separator</a></li>
  685. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  686. <li><a class="reference internal" href="#new-improved-and-deprecated-modules">New, Improved, and Deprecated Modules</a></li>
  687. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  688. <li><a class="reference internal" href="#idle">IDLE</a></li>
  689. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  690. <li><a class="reference internal" href="#porting-to-python-3-1">Porting to Python 3.1</a></li>
  691. </ul>
  692. </li>
  693. </ul>
  694. </div>
  695. <div>
  696. <h4>Previous topic</h4>
  697. <p class="topless"><a href="3.2.html"
  698. title="previous chapter">What’s New In Python 3.2</a></p>
  699. </div>
  700. <div>
  701. <h4>Next topic</h4>
  702. <p class="topless"><a href="3.0.html"
  703. title="next chapter">What’s New In Python 3.0</a></p>
  704. </div>
  705. <div role="note" aria-label="source link">
  706. <h3>This Page</h3>
  707. <ul class="this-page-menu">
  708. <li><a href="../bugs.html">Report a Bug</a></li>
  709. <li>
  710. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.1.rst"
  711. rel="nofollow">Show Source
  712. </a>
  713. </li>
  714. </ul>
  715. </div>
  716. </div>
  717. <div id="sidebarbutton" title="Collapse sidebar">
  718. <span>«</span>
  719. </div>
  720. </div>
  721. <div class="clearer"></div>
  722. </div>
  723. <div class="related" role="navigation" aria-label="related navigation">
  724. <h3>Navigation</h3>
  725. <ul>
  726. <li class="right" style="margin-right: 10px">
  727. <a href="../genindex.html" title="General Index"
  728. >index</a></li>
  729. <li class="right" >
  730. <a href="../py-modindex.html" title="Python Module Index"
  731. >modules</a> |</li>
  732. <li class="right" >
  733. <a href="3.0.html" title="What’s New In Python 3.0"
  734. >next</a> |</li>
  735. <li class="right" >
  736. <a href="3.2.html" title="What’s New In Python 3.2"
  737. >previous</a> |</li>
  738. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  739. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  740. <li class="switchers">
  741. <div class="language_switcher_placeholder"></div>
  742. <div class="version_switcher_placeholder"></div>
  743. </li>
  744. <li>
  745. </li>
  746. <li id="cpython-language-and-version">
  747. <a href="../index.html">3.12.3 Documentation</a> &#187;
  748. </li>
  749. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  750. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.1</a></li>
  751. <li class="right">
  752. <div class="inline-search" role="search">
  753. <form class="inline-search" action="../search.html" method="get">
  754. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  755. <input type="submit" value="Go" />
  756. </form>
  757. </div>
  758. |
  759. </li>
  760. <li class="right">
  761. <label class="theme-selector-label">
  762. Theme
  763. <select class="theme-selector" oninput="activateTheme(this.value)">
  764. <option value="auto" selected>Auto</option>
  765. <option value="light">Light</option>
  766. <option value="dark">Dark</option>
  767. </select>
  768. </label> |</li>
  769. </ul>
  770. </div>
  771. <div class="footer">
  772. &copy;
  773. <a href="../copyright.html">
  774. Copyright
  775. </a>
  776. 2001-2024, Python Software Foundation.
  777. <br />
  778. This page is licensed under the Python Software Foundation License Version 2.
  779. <br />
  780. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  781. <br />
  782. See <a href="/license.html">History and License</a> for more information.<br />
  783. <br />
  784. The Python Software Foundation is a non-profit corporation.
  785. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  786. <br />
  787. <br />
  788. Last updated on Apr 09, 2024 (13:47 UTC).
  789. <a href="/bugs.html">Found a bug</a>?
  790. <br />
  791. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  792. </div>
  793. </body>
  794. </html>
上海开阖软件有限公司 沪ICP备12045867号-1