1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
<html xmlns="http://www.w3.org/1999/xhtml">
7
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9
<title>25.4. 2to3 - Automated Python 2 to 3 code translation — Python 2.7.10 documentation</title>
11
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
12
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
14
<script type="text/javascript">
15
var DOCUMENTATION_OPTIONS = {
18
COLLAPSE_INDEX: false,
23
<script type="text/javascript" src="../_static/jquery.js"></script>
24
<script type="text/javascript" src="../_static/underscore.js"></script>
25
<script type="text/javascript" src="../_static/doctools.js"></script>
26
<script type="text/javascript" src="../_static/sidebar.js"></script>
27
<link rel="search" type="application/opensearchdescription+xml"
28
title="Search within Python 2.7.10 documentation"
29
href="../_static/opensearch.xml"/>
30
<link rel="author" title="About these documents" href="../about.html" />
31
<link rel="copyright" title="Copyright" href="../copyright.html" />
32
<link rel="top" title="Python 2.7.10 documentation" href="../index.html" />
33
<link rel="up" title="25. Development Tools" href="development.html" />
34
<link rel="next" title="25.5. test — Regression tests package for Python" href="test.html" />
35
<link rel="prev" title="25.3. unittest — Unit testing framework" href="unittest.html" />
36
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
<script type="text/javascript" src="../_static/copybutton.js"></script>
38
<script type="text/javascript" src="../_static/version_switch.js"></script>
47
<li class="right" style="margin-right: 10px">
48
<a href="../genindex.html" title="General Index"
49
accesskey="I">index</a></li>
51
<a href="../py-modindex.html" title="Python Module Index"
54
<a href="test.html" title="25.5. test — Regression tests package for Python"
55
accesskey="N">next</a> |</li>
57
<a href="unittest.html" title="25.3. unittest — Unit testing framework"
58
accesskey="P">previous</a> |</li>
59
<li><img src="../_static/py.png" alt=""
60
style="vertical-align: middle; margin-top: -1px"/></li>
61
<li><a href="https://www.python.org/">Python</a> »</li>
63
<span class="version_switcher_placeholder">2.7.10</span>
64
<a href="../index.html">Documentation</a> »
67
<li><a href="index.html" >The Python Standard Library</a> »</li>
68
<li><a href="development.html" accesskey="U">25. Development Tools</a> »</li>
72
<div class="document">
73
<div class="documentwrapper">
74
<div class="bodywrapper">
77
<div class="section" id="to3-automated-python-2-to-3-code-translation">
78
<span id="to3-reference"></span><h1>25.4. 2to3 - Automated Python 2 to 3 code translation<a class="headerlink" href="#to3-automated-python-2-to-3-code-translation" title="Permalink to this headline">¶</a></h1>
79
<p>2to3 is a Python program that reads Python 2.x source code and applies a series
80
of <em>fixers</em> to transform it into valid Python 3.x code. The standard library
81
contains a rich set of fixers that will handle almost all code. 2to3 supporting
82
library <a class="reference internal" href="#module-lib2to3" title="lib2to3: the 2to3 library"><tt class="xref py py-mod docutils literal"><span class="pre">lib2to3</span></tt></a> is, however, a flexible and generic library, so it is
83
possible to write your own fixers for 2to3. <a class="reference internal" href="#module-lib2to3" title="lib2to3: the 2to3 library"><tt class="xref py py-mod docutils literal"><span class="pre">lib2to3</span></tt></a> could also be
84
adapted to custom applications in which Python code needs to be edited
86
<div class="section" id="using-2to3">
87
<span id="to3-using"></span><h2>25.4.1. Using 2to3<a class="headerlink" href="#using-2to3" title="Permalink to this headline">¶</a></h2>
88
<p>2to3 will usually be installed with the Python interpreter as a script. It is
89
also located in the <tt class="file docutils literal"><span class="pre">Tools/scripts</span></tt> directory of the Python root.</p>
90
<p>2to3’s basic arguments are a list of files or directories to transform. The
91
directories are recursively traversed for Python sources.</p>
92
<p>Here is a sample Python 2.x source file, <tt class="file docutils literal"><span class="pre">example.py</span></tt>:</p>
93
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">greet</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
94
<span class="k">print</span> <span class="s">"Hello, {0}!"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
95
<span class="k">print</span> <span class="s">"What's your name?"</span>
96
<span class="n">name</span> <span class="o">=</span> <span class="nb">raw_input</span><span class="p">()</span>
97
<span class="n">greet</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
100
<p>It can be converted to Python 3.x code via 2to3 on the command line:</p>
101
<div class="highlight-python"><div class="highlight"><pre>$ 2to3 example.py
104
<p>A diff against the original source file is printed. 2to3 can also write the
105
needed modifications right back to the source file. (A backup of the original
106
file is made unless <em class="xref std std-option">-n</em> is also given.) Writing the changes back is
107
enabled with the <em class="xref std std-option">-w</em> flag:</p>
108
<div class="highlight-python"><div class="highlight"><pre>$ 2to3 -w example.py
111
<p>After transformation, <tt class="file docutils literal"><span class="pre">example.py</span></tt> looks like this:</p>
112
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">greet</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
113
<span class="k">print</span><span class="p">(</span><span class="s">"Hello, {0}!"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
114
<span class="k">print</span><span class="p">(</span><span class="s">"What's your name?"</span><span class="p">)</span>
115
<span class="n">name</span> <span class="o">=</span> <span class="nb">input</span><span class="p">()</span>
116
<span class="n">greet</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
119
<p>Comments and exact indentation are preserved throughout the translation process.</p>
120
<p>By default, 2to3 runs a set of <a class="reference internal" href="#to3-fixers"><em>predefined fixers</em></a>. The
121
<em class="xref std std-option">-l</em> flag lists all available fixers. An explicit set of fixers to run
122
can be given with <em class="xref std std-option">-f</em>. Likewise the <a class="reference internal" href="../using/cmdline.html#cmdoption-x"><em class="xref std std-option">-x</em></a> explicitly disables a
123
fixer. The following example runs only the <tt class="docutils literal"><span class="pre">imports</span></tt> and <tt class="docutils literal"><span class="pre">has_key</span></tt> fixers:</p>
124
<div class="highlight-python"><div class="highlight"><pre>$ 2to3 -f imports -f has_key example.py
127
<p>This command runs every fixer except the <tt class="docutils literal"><span class="pre">apply</span></tt> fixer:</p>
128
<div class="highlight-python"><div class="highlight"><pre>$ 2to3 -x apply example.py
131
<p>Some fixers are <em>explicit</em>, meaning they aren’t run by default and must be
132
listed on the command line to be run. Here, in addition to the default fixers,
133
the <tt class="docutils literal"><span class="pre">idioms</span></tt> fixer is run:</p>
134
<div class="highlight-python"><div class="highlight"><pre>$ 2to3 -f all -f idioms example.py
137
<p>Notice how passing <tt class="docutils literal"><span class="pre">all</span></tt> enables all default fixers.</p>
138
<p>Sometimes 2to3 will find a place in your source code that needs to be changed,
139
but 2to3 cannot fix automatically. In this case, 2to3 will print a warning
140
beneath the diff for a file. You should address the warning in order to have
141
compliant 3.x code.</p>
142
<p>2to3 can also refactor doctests. To enable this mode, use the <a class="reference internal" href="../using/cmdline.html#cmdoption-d"><em class="xref std std-option">-d</em></a>
143
flag. Note that <em>only</em> doctests will be refactored. This also doesn’t require
144
the module to be valid Python. For example, doctest like examples in a reST
145
document could also be refactored with this option.</p>
146
<p>The <a class="reference internal" href="../using/cmdline.html#cmdoption-v"><em class="xref std std-option">-v</em></a> option enables output of more information on the translation
148
<p>Since some print statements can be parsed as function calls or statements, 2to3
149
cannot always read files containing the print function. When 2to3 detects the
150
presence of the <tt class="docutils literal"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">print_function</span></tt> compiler directive, it
151
modifies its internal grammar to interpret <a class="reference internal" href="functions.html#print" title="print"><tt class="xref py py-func docutils literal"><span class="pre">print()</span></tt></a> as a function. This
152
change can also be enabled manually with the <em class="xref std std-option">-p</em> flag. Use
153
<em class="xref std std-option">-p</em> to run fixers on code that already has had its print statements
155
<p>The <em class="xref std std-option">-o</em> or <em class="xref std std-option">--output-dir</em> option allows specification of an
156
alternate directory for processed output files to be written to. The
157
<em class="xref std std-option">-n</em> flag is required when using this as backup files do not make sense
158
when not overwriting the input files.</p>
159
<div class="versionadded">
160
<p><span class="versionmodified">New in version 2.7.3: </span>The <em class="xref std std-option">-o</em> option was added.</p>
162
<p>The <a class="reference internal" href="../using/cmdline.html#cmdoption-W"><em class="xref std std-option">-W</em></a> or <em class="xref std std-option">--write-unchanged-files</em> flag tells 2to3 to always
163
write output files even if no changes were required to the file. This is most
164
useful with <em class="xref std std-option">-o</em> so that an entire Python source tree is copied with
165
translation from one directory to another.
166
This option implies the <em class="xref std std-option">-w</em> flag as it would not make sense otherwise.</p>
167
<div class="versionadded">
168
<p><span class="versionmodified">New in version 2.7.3: </span>The <a class="reference internal" href="../using/cmdline.html#cmdoption-W"><em class="xref std std-option">-W</em></a> flag was added.</p>
170
<p>The <em class="xref std std-option">--add-suffix</em> option specifies a string to append to all output
171
filenames. The <em class="xref std std-option">-n</em> flag is required when specifying this as backups
172
are not necessary when writing to different filenames. Example:</p>
173
<div class="highlight-python"><div class="highlight"><pre>$ 2to3 -n -W --add-suffix=3 example.py
176
<p>Will cause a converted file named <tt class="docutils literal"><span class="pre">example.py3</span></tt> to be written.</p>
177
<div class="versionadded">
178
<p><span class="versionmodified">New in version 2.7.3: </span>The <em class="xref std std-option">--add-suffix</em> option was added.</p>
180
<p>To translate an entire project from one directory tree to another use:</p>
181
<div class="highlight-python"><div class="highlight"><pre>$ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode
185
<div class="section" id="fixers">
186
<span id="to3-fixers"></span><h2>25.4.2. Fixers<a class="headerlink" href="#fixers" title="Permalink to this headline">¶</a></h2>
187
<p>Each step of transforming code is encapsulated in a fixer. The command <tt class="docutils literal"><span class="pre">2to3</span>
188
<span class="pre">-l</span></tt> lists them. As <a class="reference internal" href="#to3-using"><em>documented above</em></a>, each can be turned on
189
and off individually. They are described here in more detail.</p>
190
<dl class="2to3fixer">
191
<dt id="2to3fixer-apply">
192
<tt class="descname">apply</tt><a class="headerlink" href="#2to3fixer-apply" title="Permalink to this definition">¶</a></dt>
193
<dd><p>Removes usage of <a class="reference internal" href="functions.html#apply" title="apply"><tt class="xref py py-func docutils literal"><span class="pre">apply()</span></tt></a>. For example <tt class="docutils literal"><span class="pre">apply(function,</span> <span class="pre">*args,</span>
194
<span class="pre">**kwargs)</span></tt> is converted to <tt class="docutils literal"><span class="pre">function(*args,</span> <span class="pre">**kwargs)</span></tt>.</p>
197
<dl class="2to3fixer">
198
<dt id="2to3fixer-asserts">
199
<tt class="descname">asserts</tt><a class="headerlink" href="#2to3fixer-asserts" title="Permalink to this definition">¶</a></dt>
200
<dd><p>Replaces deprecated <a class="reference internal" href="unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><tt class="xref py py-mod docutils literal"><span class="pre">unittest</span></tt></a> method names with the correct ones.</p>
201
<table border="1" class="docutils">
206
<thead valign="bottom">
207
<tr class="row-odd"><th class="head">From</th>
208
<th class="head">To</th>
212
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">failUnlessEqual(a,</span> <span class="pre">b)</span></tt></td>
213
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertEqual" title="unittest.TestCase.assertEqual"><tt class="xref py py-meth docutils literal"><span class="pre">assertEqual(a,</span> <span class="pre">b)</span></tt></a></td>
215
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">assertEquals(a,</span> <span class="pre">b)</span></tt></td>
216
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertEqual" title="unittest.TestCase.assertEqual"><tt class="xref py py-meth docutils literal"><span class="pre">assertEqual(a,</span> <span class="pre">b)</span></tt></a></td>
218
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">failIfEqual(a,</span> <span class="pre">b)</span></tt></td>
219
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertNotEqual" title="unittest.TestCase.assertNotEqual"><tt class="xref py py-meth docutils literal"><span class="pre">assertNotEqual(a,</span> <span class="pre">b)</span></tt></a></td>
221
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">assertNotEquals(a,</span> <span class="pre">b)</span></tt></td>
222
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertNotEqual" title="unittest.TestCase.assertNotEqual"><tt class="xref py py-meth docutils literal"><span class="pre">assertNotEqual(a,</span> <span class="pre">b)</span></tt></a></td>
224
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">failUnless(a)</span></tt></td>
225
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertTrue" title="unittest.TestCase.assertTrue"><tt class="xref py py-meth docutils literal"><span class="pre">assertTrue(a)</span></tt></a></td>
227
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">assert_(a)</span></tt></td>
228
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertTrue" title="unittest.TestCase.assertTrue"><tt class="xref py py-meth docutils literal"><span class="pre">assertTrue(a)</span></tt></a></td>
230
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">failIf(a)</span></tt></td>
231
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertFalse" title="unittest.TestCase.assertFalse"><tt class="xref py py-meth docutils literal"><span class="pre">assertFalse(a)</span></tt></a></td>
233
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">failUnlessRaises(exc,</span> <span class="pre">cal)</span></tt></td>
234
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertRaises" title="unittest.TestCase.assertRaises"><tt class="xref py py-meth docutils literal"><span class="pre">assertRaises(exc,</span> <span class="pre">cal)</span></tt></a></td>
236
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">failUnlessAlmostEqual(a,</span> <span class="pre">b)</span></tt></td>
237
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertAlmostEqual" title="unittest.TestCase.assertAlmostEqual"><tt class="xref py py-meth docutils literal"><span class="pre">assertAlmostEqual(a,</span> <span class="pre">b)</span></tt></a></td>
239
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">assertAlmostEquals(a,</span> <span class="pre">b)</span></tt></td>
240
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertAlmostEqual" title="unittest.TestCase.assertAlmostEqual"><tt class="xref py py-meth docutils literal"><span class="pre">assertAlmostEqual(a,</span> <span class="pre">b)</span></tt></a></td>
242
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">failIfAlmostEqual(a,</span> <span class="pre">b)</span></tt></td>
243
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertNotAlmostEqual" title="unittest.TestCase.assertNotAlmostEqual"><tt class="xref py py-meth docutils literal"><span class="pre">assertNotAlmostEqual(a,</span> <span class="pre">b)</span></tt></a></td>
245
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">assertNotAlmostEquals(a,</span> <span class="pre">b)</span></tt></td>
246
<td><a class="reference internal" href="unittest.html#unittest.TestCase.assertNotAlmostEqual" title="unittest.TestCase.assertNotAlmostEqual"><tt class="xref py py-meth docutils literal"><span class="pre">assertNotAlmostEqual(a,</span> <span class="pre">b)</span></tt></a></td>
252
<dl class="2to3fixer">
253
<dt id="2to3fixer-basestring">
254
<tt class="descname">basestring</tt><a class="headerlink" href="#2to3fixer-basestring" title="Permalink to this definition">¶</a></dt>
255
<dd><p>Converts <a class="reference internal" href="functions.html#basestring" title="basestring"><tt class="xref py py-class docutils literal"><span class="pre">basestring</span></tt></a> to <a class="reference internal" href="functions.html#str" title="str"><tt class="xref py py-class docutils literal"><span class="pre">str</span></tt></a>.</p>
258
<dl class="2to3fixer">
259
<dt id="2to3fixer-buffer">
260
<tt class="descname">buffer</tt><a class="headerlink" href="#2to3fixer-buffer" title="Permalink to this definition">¶</a></dt>
261
<dd><p>Converts <a class="reference internal" href="functions.html#buffer" title="buffer"><tt class="xref py py-class docutils literal"><span class="pre">buffer</span></tt></a> to <a class="reference internal" href="stdtypes.html#memoryview" title="memoryview"><tt class="xref py py-class docutils literal"><span class="pre">memoryview</span></tt></a>. This fixer is optional
262
because the <a class="reference internal" href="stdtypes.html#memoryview" title="memoryview"><tt class="xref py py-class docutils literal"><span class="pre">memoryview</span></tt></a> API is similar but not exactly the same as
263
that of <a class="reference internal" href="functions.html#buffer" title="buffer"><tt class="xref py py-class docutils literal"><span class="pre">buffer</span></tt></a>.</p>
266
<dl class="2to3fixer">
267
<dt id="2to3fixer-callable">
268
<tt class="descname">callable</tt><a class="headerlink" href="#2to3fixer-callable" title="Permalink to this definition">¶</a></dt>
269
<dd><p>Converts <tt class="docutils literal"><span class="pre">callable(x)</span></tt> to <tt class="docutils literal"><span class="pre">isinstance(x,</span> <span class="pre">collections.Callable)</span></tt>, adding
270
an import to <a class="reference internal" href="collections.html#module-collections" title="collections: High-performance datatypes"><tt class="xref py py-mod docutils literal"><span class="pre">collections</span></tt></a> if needed. Note <tt class="docutils literal"><span class="pre">callable(x)</span></tt> has returned
271
in Python 3.2, so if you do not intend to support Python 3.1, you can disable
275
<dl class="2to3fixer">
276
<dt id="2to3fixer-dict">
277
<tt class="descname">dict</tt><a class="headerlink" href="#2to3fixer-dict" title="Permalink to this definition">¶</a></dt>
278
<dd><p>Fixes dictionary iteration methods. <a class="reference internal" href="stdtypes.html#dict.iteritems" title="dict.iteritems"><tt class="xref py py-meth docutils literal"><span class="pre">dict.iteritems()</span></tt></a> is converted to
279
<a class="reference internal" href="stdtypes.html#dict.items" title="dict.items"><tt class="xref py py-meth docutils literal"><span class="pre">dict.items()</span></tt></a>, <a class="reference internal" href="stdtypes.html#dict.iterkeys" title="dict.iterkeys"><tt class="xref py py-meth docutils literal"><span class="pre">dict.iterkeys()</span></tt></a> to <a class="reference internal" href="stdtypes.html#dict.keys" title="dict.keys"><tt class="xref py py-meth docutils literal"><span class="pre">dict.keys()</span></tt></a>, and
280
<a class="reference internal" href="stdtypes.html#dict.itervalues" title="dict.itervalues"><tt class="xref py py-meth docutils literal"><span class="pre">dict.itervalues()</span></tt></a> to <a class="reference internal" href="stdtypes.html#dict.values" title="dict.values"><tt class="xref py py-meth docutils literal"><span class="pre">dict.values()</span></tt></a>. Similarly,
281
<a class="reference internal" href="stdtypes.html#dict.viewitems" title="dict.viewitems"><tt class="xref py py-meth docutils literal"><span class="pre">dict.viewitems()</span></tt></a>, <a class="reference internal" href="stdtypes.html#dict.viewkeys" title="dict.viewkeys"><tt class="xref py py-meth docutils literal"><span class="pre">dict.viewkeys()</span></tt></a> and <a class="reference internal" href="stdtypes.html#dict.viewvalues" title="dict.viewvalues"><tt class="xref py py-meth docutils literal"><span class="pre">dict.viewvalues()</span></tt></a> are
282
converted respectively to <a class="reference internal" href="stdtypes.html#dict.items" title="dict.items"><tt class="xref py py-meth docutils literal"><span class="pre">dict.items()</span></tt></a>, <a class="reference internal" href="stdtypes.html#dict.keys" title="dict.keys"><tt class="xref py py-meth docutils literal"><span class="pre">dict.keys()</span></tt></a> and
283
<a class="reference internal" href="stdtypes.html#dict.values" title="dict.values"><tt class="xref py py-meth docutils literal"><span class="pre">dict.values()</span></tt></a>. It also wraps existing usages of <a class="reference internal" href="stdtypes.html#dict.items" title="dict.items"><tt class="xref py py-meth docutils literal"><span class="pre">dict.items()</span></tt></a>,
284
<a class="reference internal" href="stdtypes.html#dict.keys" title="dict.keys"><tt class="xref py py-meth docutils literal"><span class="pre">dict.keys()</span></tt></a>, and <a class="reference internal" href="stdtypes.html#dict.values" title="dict.values"><tt class="xref py py-meth docutils literal"><span class="pre">dict.values()</span></tt></a> in a call to <a class="reference internal" href="functions.html#list" title="list"><tt class="xref py py-class docutils literal"><span class="pre">list</span></tt></a>.</p>
287
<dl class="2to3fixer">
288
<dt id="2to3fixer-except">
289
<tt class="descname">except</tt><a class="headerlink" href="#2to3fixer-except" title="Permalink to this definition">¶</a></dt>
290
<dd><p>Converts <tt class="docutils literal"><span class="pre">except</span> <span class="pre">X,</span> <span class="pre">T</span></tt> to <tt class="docutils literal"><span class="pre">except</span> <span class="pre">X</span> <span class="pre">as</span> <span class="pre">T</span></tt>.</p>
293
<dl class="2to3fixer">
294
<dt id="2to3fixer-exec">
295
<tt class="descname">exec</tt><a class="headerlink" href="#2to3fixer-exec" title="Permalink to this definition">¶</a></dt>
296
<dd><p>Converts the <a class="reference internal" href="../reference/simple_stmts.html#exec"><tt class="xref std std-keyword docutils literal"><span class="pre">exec</span></tt></a> statement to the <tt class="xref py py-func docutils literal"><span class="pre">exec()</span></tt> function.</p>
299
<dl class="2to3fixer">
300
<dt id="2to3fixer-execfile">
301
<tt class="descname">execfile</tt><a class="headerlink" href="#2to3fixer-execfile" title="Permalink to this definition">¶</a></dt>
302
<dd><p>Removes usage of <a class="reference internal" href="functions.html#execfile" title="execfile"><tt class="xref py py-func docutils literal"><span class="pre">execfile()</span></tt></a>. The argument to <a class="reference internal" href="functions.html#execfile" title="execfile"><tt class="xref py py-func docutils literal"><span class="pre">execfile()</span></tt></a> is
303
wrapped in calls to <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>, <a class="reference internal" href="functions.html#compile" title="compile"><tt class="xref py py-func docutils literal"><span class="pre">compile()</span></tt></a>, and <tt class="xref py py-func docutils literal"><span class="pre">exec()</span></tt>.</p>
306
<dl class="2to3fixer">
307
<dt id="2to3fixer-exitfunc">
308
<tt class="descname">exitfunc</tt><a class="headerlink" href="#2to3fixer-exitfunc" title="Permalink to this definition">¶</a></dt>
309
<dd><p>Changes assignment of <a class="reference internal" href="sys.html#sys.exitfunc" title="sys.exitfunc"><tt class="xref py py-attr docutils literal"><span class="pre">sys.exitfunc</span></tt></a> to use of the <a class="reference internal" href="atexit.html#module-atexit" title="atexit: Register and execute cleanup functions."><tt class="xref py py-mod docutils literal"><span class="pre">atexit</span></tt></a>
313
<dl class="2to3fixer">
314
<dt id="2to3fixer-filter">
315
<tt class="descname">filter</tt><a class="headerlink" href="#2to3fixer-filter" title="Permalink to this definition">¶</a></dt>
316
<dd><p>Wraps <a class="reference internal" href="functions.html#filter" title="filter"><tt class="xref py py-func docutils literal"><span class="pre">filter()</span></tt></a> usage in a <a class="reference internal" href="functions.html#list" title="list"><tt class="xref py py-class docutils literal"><span class="pre">list</span></tt></a> call.</p>
319
<dl class="2to3fixer">
320
<dt id="2to3fixer-funcattrs">
321
<tt class="descname">funcattrs</tt><a class="headerlink" href="#2to3fixer-funcattrs" title="Permalink to this definition">¶</a></dt>
322
<dd><p>Fixes function attributes that have been renamed. For example,
323
<tt class="docutils literal"><span class="pre">my_function.func_closure</span></tt> is converted to <tt class="docutils literal"><span class="pre">my_function.__closure__</span></tt>.</p>
326
<dl class="2to3fixer">
327
<dt id="2to3fixer-future">
328
<tt class="descname">future</tt><a class="headerlink" href="#2to3fixer-future" title="Permalink to this definition">¶</a></dt>
329
<dd><p>Removes <tt class="docutils literal"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">new_feature</span></tt> statements.</p>
332
<dl class="2to3fixer">
333
<dt id="2to3fixer-getcwdu">
334
<tt class="descname">getcwdu</tt><a class="headerlink" href="#2to3fixer-getcwdu" title="Permalink to this definition">¶</a></dt>
335
<dd><p>Renames <a class="reference internal" href="os.html#os.getcwdu" title="os.getcwdu"><tt class="xref py py-func docutils literal"><span class="pre">os.getcwdu()</span></tt></a> to <a class="reference internal" href="os.html#os.getcwd" title="os.getcwd"><tt class="xref py py-func docutils literal"><span class="pre">os.getcwd()</span></tt></a>.</p>
338
<dl class="2to3fixer">
339
<dt id="2to3fixer-has_key">
340
<tt class="descname">has_key</tt><a class="headerlink" href="#2to3fixer-has_key" title="Permalink to this definition">¶</a></dt>
341
<dd><p>Changes <tt class="docutils literal"><span class="pre">dict.has_key(key)</span></tt> to <tt class="docutils literal"><span class="pre">key</span> <span class="pre">in</span> <span class="pre">dict</span></tt>.</p>
344
<dl class="2to3fixer">
345
<dt id="2to3fixer-idioms">
346
<tt class="descname">idioms</tt><a class="headerlink" href="#2to3fixer-idioms" title="Permalink to this definition">¶</a></dt>
347
<dd><p>This optional fixer performs several transformations that make Python code
348
more idiomatic. Type comparisons like <tt class="docutils literal"><span class="pre">type(x)</span> <span class="pre">is</span> <span class="pre">SomeClass</span></tt> and
349
<tt class="docutils literal"><span class="pre">type(x)</span> <span class="pre">==</span> <span class="pre">SomeClass</span></tt> are converted to <tt class="docutils literal"><span class="pre">isinstance(x,</span> <span class="pre">SomeClass)</span></tt>.
350
<tt class="docutils literal"><span class="pre">while</span> <span class="pre">1</span></tt> becomes <tt class="docutils literal"><span class="pre">while</span> <span class="pre">True</span></tt>. This fixer also tries to make use of
351
<a class="reference internal" href="functions.html#sorted" title="sorted"><tt class="xref py py-func docutils literal"><span class="pre">sorted()</span></tt></a> in appropriate places. For example, this block</p>
352
<div class="highlight-python"><div class="highlight"><pre><span class="n">L</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">some_iterable</span><span class="p">)</span>
353
<span class="n">L</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
357
<div class="highlight-python"><div class="highlight"><pre><span class="n">L</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">some_iterable</span><span class="p">)</span>
362
<dl class="2to3fixer">
363
<dt id="2to3fixer-import">
364
<tt class="descname">import</tt><a class="headerlink" href="#2to3fixer-import" title="Permalink to this definition">¶</a></dt>
365
<dd><p>Detects sibling imports and converts them to relative imports.</p>
368
<dl class="2to3fixer">
369
<dt id="2to3fixer-imports">
370
<tt class="descname">imports</tt><a class="headerlink" href="#2to3fixer-imports" title="Permalink to this definition">¶</a></dt>
371
<dd><p>Handles module renames in the standard library.</p>
374
<dl class="2to3fixer">
375
<dt id="2to3fixer-imports2">
376
<tt class="descname">imports2</tt><a class="headerlink" href="#2to3fixer-imports2" title="Permalink to this definition">¶</a></dt>
377
<dd><p>Handles other modules renames in the standard library. It is separate from
378
the <a class="reference internal" href="#2to3fixer-imports"><tt class="xref std std-2to3fixer docutils literal"><span class="pre">imports</span></tt></a> fixer only because of technical limitations.</p>
381
<dl class="2to3fixer">
382
<dt id="2to3fixer-input">
383
<tt class="descname">input</tt><a class="headerlink" href="#2to3fixer-input" title="Permalink to this definition">¶</a></dt>
384
<dd><p>Converts <tt class="docutils literal"><span class="pre">input(prompt)</span></tt> to <tt class="docutils literal"><span class="pre">eval(input(prompt))</span></tt></p>
387
<dl class="2to3fixer">
388
<dt id="2to3fixer-intern">
389
<tt class="descname">intern</tt><a class="headerlink" href="#2to3fixer-intern" title="Permalink to this definition">¶</a></dt>
390
<dd><p>Converts <a class="reference internal" href="functions.html#intern" title="intern"><tt class="xref py py-func docutils literal"><span class="pre">intern()</span></tt></a> to <tt class="xref py py-func docutils literal"><span class="pre">sys.intern()</span></tt>.</p>
393
<dl class="2to3fixer">
394
<dt id="2to3fixer-isinstance">
395
<tt class="descname">isinstance</tt><a class="headerlink" href="#2to3fixer-isinstance" title="Permalink to this definition">¶</a></dt>
396
<dd><p>Fixes duplicate types in the second argument of <a class="reference internal" href="functions.html#isinstance" title="isinstance"><tt class="xref py py-func docutils literal"><span class="pre">isinstance()</span></tt></a>. For
397
example, <tt class="docutils literal"><span class="pre">isinstance(x,</span> <span class="pre">(int,</span> <span class="pre">int))</span></tt> is converted to <tt class="docutils literal"><span class="pre">isinstance(x,</span>
398
<span class="pre">(int))</span></tt>.</p>
401
<dl class="2to3fixer">
402
<dt id="2to3fixer-itertools_imports">
403
<tt class="descname">itertools_imports</tt><a class="headerlink" href="#2to3fixer-itertools_imports" title="Permalink to this definition">¶</a></dt>
404
<dd><p>Removes imports of <a class="reference internal" href="itertools.html#itertools.ifilter" title="itertools.ifilter"><tt class="xref py py-func docutils literal"><span class="pre">itertools.ifilter()</span></tt></a>, <a class="reference internal" href="itertools.html#itertools.izip" title="itertools.izip"><tt class="xref py py-func docutils literal"><span class="pre">itertools.izip()</span></tt></a>, and
405
<a class="reference internal" href="itertools.html#itertools.imap" title="itertools.imap"><tt class="xref py py-func docutils literal"><span class="pre">itertools.imap()</span></tt></a>. Imports of <a class="reference internal" href="itertools.html#itertools.ifilterfalse" title="itertools.ifilterfalse"><tt class="xref py py-func docutils literal"><span class="pre">itertools.ifilterfalse()</span></tt></a> are also
406
changed to <tt class="xref py py-func docutils literal"><span class="pre">itertools.filterfalse()</span></tt>.</p>
409
<dl class="2to3fixer">
410
<dt id="2to3fixer-itertools">
411
<tt class="descname">itertools</tt><a class="headerlink" href="#2to3fixer-itertools" title="Permalink to this definition">¶</a></dt>
412
<dd><p>Changes usage of <a class="reference internal" href="itertools.html#itertools.ifilter" title="itertools.ifilter"><tt class="xref py py-func docutils literal"><span class="pre">itertools.ifilter()</span></tt></a>, <a class="reference internal" href="itertools.html#itertools.izip" title="itertools.izip"><tt class="xref py py-func docutils literal"><span class="pre">itertools.izip()</span></tt></a>, and
413
<a class="reference internal" href="itertools.html#itertools.imap" title="itertools.imap"><tt class="xref py py-func docutils literal"><span class="pre">itertools.imap()</span></tt></a> to their built-in equivalents.
414
<a class="reference internal" href="itertools.html#itertools.ifilterfalse" title="itertools.ifilterfalse"><tt class="xref py py-func docutils literal"><span class="pre">itertools.ifilterfalse()</span></tt></a> is changed to <tt class="xref py py-func docutils literal"><span class="pre">itertools.filterfalse()</span></tt>.</p>
417
<dl class="2to3fixer">
418
<dt id="2to3fixer-long">
419
<tt class="descname">long</tt><a class="headerlink" href="#2to3fixer-long" title="Permalink to this definition">¶</a></dt>
420
<dd><p>Renames <a class="reference internal" href="functions.html#long" title="long"><tt class="xref py py-class docutils literal"><span class="pre">long</span></tt></a> to <a class="reference internal" href="functions.html#int" title="int"><tt class="xref py py-class docutils literal"><span class="pre">int</span></tt></a>.</p>
423
<dl class="2to3fixer">
424
<dt id="2to3fixer-map">
425
<tt class="descname">map</tt><a class="headerlink" href="#2to3fixer-map" title="Permalink to this definition">¶</a></dt>
426
<dd><p>Wraps <a class="reference internal" href="functions.html#map" title="map"><tt class="xref py py-func docutils literal"><span class="pre">map()</span></tt></a> in a <a class="reference internal" href="functions.html#list" title="list"><tt class="xref py py-class docutils literal"><span class="pre">list</span></tt></a> call. It also changes <tt class="docutils literal"><span class="pre">map(None,</span> <span class="pre">x)</span></tt>
427
to <tt class="docutils literal"><span class="pre">list(x)</span></tt>. Using <tt class="docutils literal"><span class="pre">from</span> <span class="pre">future_builtins</span> <span class="pre">import</span> <span class="pre">map</span></tt> disables this
431
<dl class="2to3fixer">
432
<dt id="2to3fixer-metaclass">
433
<tt class="descname">metaclass</tt><a class="headerlink" href="#2to3fixer-metaclass" title="Permalink to this definition">¶</a></dt>
434
<dd><p>Converts the old metaclass syntax (<tt class="docutils literal"><span class="pre">__metaclass__</span> <span class="pre">=</span> <span class="pre">Meta</span></tt> in the class
435
body) to the new (<tt class="docutils literal"><span class="pre">class</span> <span class="pre">X(metaclass=Meta)</span></tt>).</p>
438
<dl class="2to3fixer">
439
<dt id="2to3fixer-methodattrs">
440
<tt class="descname">methodattrs</tt><a class="headerlink" href="#2to3fixer-methodattrs" title="Permalink to this definition">¶</a></dt>
441
<dd><p>Fixes old method attribute names. For example, <tt class="docutils literal"><span class="pre">meth.im_func</span></tt> is converted
442
to <tt class="docutils literal"><span class="pre">meth.__func__</span></tt>.</p>
445
<dl class="2to3fixer">
446
<dt id="2to3fixer-ne">
447
<tt class="descname">ne</tt><a class="headerlink" href="#2to3fixer-ne" title="Permalink to this definition">¶</a></dt>
448
<dd><p>Converts the old not-equal syntax, <tt class="docutils literal"><span class="pre"><></span></tt>, to <tt class="docutils literal"><span class="pre">!=</span></tt>.</p>
451
<dl class="2to3fixer">
452
<dt id="2to3fixer-next">
453
<tt class="descname">next</tt><a class="headerlink" href="#2to3fixer-next" title="Permalink to this definition">¶</a></dt>
454
<dd><p>Converts the use of iterator’s <a class="reference internal" href="stdtypes.html#iterator.next" title="iterator.next"><tt class="xref py py-meth docutils literal"><span class="pre">next()</span></tt></a> methods to the
455
<a class="reference internal" href="functions.html#next" title="next"><tt class="xref py py-func docutils literal"><span class="pre">next()</span></tt></a> function. It also renames <a class="reference internal" href="stdtypes.html#iterator.next" title="iterator.next"><tt class="xref py py-meth docutils literal"><span class="pre">next()</span></tt></a> methods to
456
<tt class="xref py py-meth docutils literal"><span class="pre">__next__()</span></tt>.</p>
459
<dl class="2to3fixer">
460
<dt id="2to3fixer-nonzero">
461
<tt class="descname">nonzero</tt><a class="headerlink" href="#2to3fixer-nonzero" title="Permalink to this definition">¶</a></dt>
462
<dd><p>Renames <a class="reference internal" href="../reference/datamodel.html#object.__nonzero__" title="object.__nonzero__"><tt class="xref py py-meth docutils literal"><span class="pre">__nonzero__()</span></tt></a> to <tt class="xref py py-meth docutils literal"><span class="pre">__bool__()</span></tt>.</p>
465
<dl class="2to3fixer">
466
<dt id="2to3fixer-numliterals">
467
<tt class="descname">numliterals</tt><a class="headerlink" href="#2to3fixer-numliterals" title="Permalink to this definition">¶</a></dt>
468
<dd><p>Converts octal literals into the new syntax.</p>
471
<dl class="2to3fixer">
472
<dt id="2to3fixer-paren">
473
<tt class="descname">paren</tt><a class="headerlink" href="#2to3fixer-paren" title="Permalink to this definition">¶</a></dt>
474
<dd><p>Add extra parenthesis where they are required in list comprehensions. For
475
example, <tt class="docutils literal"><span class="pre">[x</span> <span class="pre">for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">1,</span> <span class="pre">2]</span></tt> becomes <tt class="docutils literal"><span class="pre">[x</span> <span class="pre">for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">(1,</span> <span class="pre">2)]</span></tt>.</p>
478
<dl class="2to3fixer">
479
<dt id="2to3fixer-print">
480
<tt class="descname">print</tt><a class="headerlink" href="#2to3fixer-print" title="Permalink to this definition">¶</a></dt>
481
<dd><p>Converts the <a class="reference internal" href="../reference/simple_stmts.html#print"><tt class="xref std std-keyword docutils literal"><span class="pre">print</span></tt></a> statement to the <a class="reference internal" href="functions.html#print" title="print"><tt class="xref py py-func docutils literal"><span class="pre">print()</span></tt></a> function.</p>
484
<dl class="2to3fixer">
485
<dt id="2to3fixer-raise">
486
<tt class="descname">raise</tt><a class="headerlink" href="#2to3fixer-raise" title="Permalink to this definition">¶</a></dt>
487
<dd><p>Converts <tt class="docutils literal"><span class="pre">raise</span> <span class="pre">E,</span> <span class="pre">V</span></tt> to <tt class="docutils literal"><span class="pre">raise</span> <span class="pre">E(V)</span></tt>, and <tt class="docutils literal"><span class="pre">raise</span> <span class="pre">E,</span> <span class="pre">V,</span> <span class="pre">T</span></tt> to <tt class="docutils literal"><span class="pre">raise</span>
488
<span class="pre">E(V).with_traceback(T)</span></tt>. If <tt class="docutils literal"><span class="pre">E</span></tt> is a tuple, the translation will be
489
incorrect because substituting tuples for exceptions has been removed in Python 3.</p>
492
<dl class="2to3fixer">
493
<dt id="2to3fixer-raw_input">
494
<tt class="descname">raw_input</tt><a class="headerlink" href="#2to3fixer-raw_input" title="Permalink to this definition">¶</a></dt>
495
<dd><p>Converts <a class="reference internal" href="functions.html#raw_input" title="raw_input"><tt class="xref py py-func docutils literal"><span class="pre">raw_input()</span></tt></a> to <a class="reference internal" href="functions.html#input" title="input"><tt class="xref py py-func docutils literal"><span class="pre">input()</span></tt></a>.</p>
498
<dl class="2to3fixer">
499
<dt id="2to3fixer-reduce">
500
<tt class="descname">reduce</tt><a class="headerlink" href="#2to3fixer-reduce" title="Permalink to this definition">¶</a></dt>
501
<dd><p>Handles the move of <a class="reference internal" href="functions.html#reduce" title="reduce"><tt class="xref py py-func docutils literal"><span class="pre">reduce()</span></tt></a> to <a class="reference internal" href="functools.html#functools.reduce" title="functools.reduce"><tt class="xref py py-func docutils literal"><span class="pre">functools.reduce()</span></tt></a>.</p>
504
<dl class="2to3fixer">
505
<dt id="2to3fixer-renames">
506
<tt class="descname">renames</tt><a class="headerlink" href="#2to3fixer-renames" title="Permalink to this definition">¶</a></dt>
507
<dd><p>Changes <a class="reference internal" href="sys.html#sys.maxint" title="sys.maxint"><tt class="xref py py-data docutils literal"><span class="pre">sys.maxint</span></tt></a> to <a class="reference internal" href="sys.html#sys.maxsize" title="sys.maxsize"><tt class="xref py py-data docutils literal"><span class="pre">sys.maxsize</span></tt></a>.</p>
510
<dl class="2to3fixer">
511
<dt id="2to3fixer-repr">
512
<tt class="descname">repr</tt><a class="headerlink" href="#2to3fixer-repr" title="Permalink to this definition">¶</a></dt>
513
<dd><p>Replaces backtick repr with the <a class="reference internal" href="functions.html#repr" title="repr"><tt class="xref py py-func docutils literal"><span class="pre">repr()</span></tt></a> function.</p>
516
<dl class="2to3fixer">
517
<dt id="2to3fixer-set_literal">
518
<tt class="descname">set_literal</tt><a class="headerlink" href="#2to3fixer-set_literal" title="Permalink to this definition">¶</a></dt>
519
<dd><p>Replaces use of the <a class="reference internal" href="stdtypes.html#set" title="set"><tt class="xref py py-class docutils literal"><span class="pre">set</span></tt></a> constructor with set literals. This fixer
523
<dl class="2to3fixer">
524
<dt id="2to3fixer-standarderror">
525
<tt class="descname">standarderror</tt><a class="headerlink" href="#2to3fixer-standarderror" title="Permalink to this definition">¶</a></dt>
526
<dd><p>Renames <a class="reference internal" href="exceptions.html#exceptions.StandardError" title="exceptions.StandardError"><tt class="xref py py-exc docutils literal"><span class="pre">StandardError</span></tt></a> to <a class="reference internal" href="exceptions.html#exceptions.Exception" title="exceptions.Exception"><tt class="xref py py-exc docutils literal"><span class="pre">Exception</span></tt></a>.</p>
529
<dl class="2to3fixer">
530
<dt id="2to3fixer-sys_exc">
531
<tt class="descname">sys_exc</tt><a class="headerlink" href="#2to3fixer-sys_exc" title="Permalink to this definition">¶</a></dt>
532
<dd><p>Changes the deprecated <a class="reference internal" href="sys.html#sys.exc_value" title="sys.exc_value"><tt class="xref py py-data docutils literal"><span class="pre">sys.exc_value</span></tt></a>, <a class="reference internal" href="sys.html#sys.exc_type" title="sys.exc_type"><tt class="xref py py-data docutils literal"><span class="pre">sys.exc_type</span></tt></a>,
533
<a class="reference internal" href="sys.html#sys.exc_traceback" title="sys.exc_traceback"><tt class="xref py py-data docutils literal"><span class="pre">sys.exc_traceback</span></tt></a> to use <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><tt class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></tt></a>.</p>
536
<dl class="2to3fixer">
537
<dt id="2to3fixer-throw">
538
<tt class="descname">throw</tt><a class="headerlink" href="#2to3fixer-throw" title="Permalink to this definition">¶</a></dt>
539
<dd><p>Fixes the API change in generator’s <tt class="xref py py-meth docutils literal"><span class="pre">throw()</span></tt> method.</p>
542
<dl class="2to3fixer">
543
<dt id="2to3fixer-tuple_params">
544
<tt class="descname">tuple_params</tt><a class="headerlink" href="#2to3fixer-tuple_params" title="Permalink to this definition">¶</a></dt>
545
<dd><p>Removes implicit tuple parameter unpacking. This fixer inserts temporary
549
<dl class="2to3fixer">
550
<dt id="2to3fixer-types">
551
<tt class="descname">types</tt><a class="headerlink" href="#2to3fixer-types" title="Permalink to this definition">¶</a></dt>
552
<dd><p>Fixes code broken from the removal of some members in the <a class="reference internal" href="types.html#module-types" title="types: Names for built-in types."><tt class="xref py py-mod docutils literal"><span class="pre">types</span></tt></a>
556
<dl class="2to3fixer">
557
<dt id="2to3fixer-unicode">
558
<tt class="descname">unicode</tt><a class="headerlink" href="#2to3fixer-unicode" title="Permalink to this definition">¶</a></dt>
559
<dd><p>Renames <a class="reference internal" href="functions.html#unicode" title="unicode"><tt class="xref py py-class docutils literal"><span class="pre">unicode</span></tt></a> to <a class="reference internal" href="functions.html#str" title="str"><tt class="xref py py-class docutils literal"><span class="pre">str</span></tt></a>.</p>
562
<dl class="2to3fixer">
563
<dt id="2to3fixer-urllib">
564
<tt class="descname">urllib</tt><a class="headerlink" href="#2to3fixer-urllib" title="Permalink to this definition">¶</a></dt>
565
<dd><p>Handles the rename of <a class="reference internal" href="urllib.html#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><tt class="xref py py-mod docutils literal"><span class="pre">urllib</span></tt></a> and <a class="reference internal" href="urllib2.html#module-urllib2" title="urllib2: Next generation URL opening library."><tt class="xref py py-mod docutils literal"><span class="pre">urllib2</span></tt></a> to the <a class="reference internal" href="urllib.html#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><tt class="xref py py-mod docutils literal"><span class="pre">urllib</span></tt></a>
569
<dl class="2to3fixer">
570
<dt id="2to3fixer-ws_comma">
571
<tt class="descname">ws_comma</tt><a class="headerlink" href="#2to3fixer-ws_comma" title="Permalink to this definition">¶</a></dt>
572
<dd><p>Removes excess whitespace from comma separated items. This fixer is
576
<dl class="2to3fixer">
577
<dt id="2to3fixer-xrange">
578
<tt class="descname">xrange</tt><a class="headerlink" href="#2to3fixer-xrange" title="Permalink to this definition">¶</a></dt>
579
<dd><p>Renames <a class="reference internal" href="functions.html#xrange" title="xrange"><tt class="xref py py-func docutils literal"><span class="pre">xrange()</span></tt></a> to <a class="reference internal" href="functions.html#range" title="range"><tt class="xref py py-func docutils literal"><span class="pre">range()</span></tt></a> and wraps existing <a class="reference internal" href="functions.html#range" title="range"><tt class="xref py py-func docutils literal"><span class="pre">range()</span></tt></a>
580
calls with <a class="reference internal" href="functions.html#list" title="list"><tt class="xref py py-class docutils literal"><span class="pre">list</span></tt></a>.</p>
583
<dl class="2to3fixer">
584
<dt id="2to3fixer-xreadlines">
585
<tt class="descname">xreadlines</tt><a class="headerlink" href="#2to3fixer-xreadlines" title="Permalink to this definition">¶</a></dt>
586
<dd><p>Changes <tt class="docutils literal"><span class="pre">for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">file.xreadlines()</span></tt> to <tt class="docutils literal"><span class="pre">for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">file</span></tt>.</p>
589
<dl class="2to3fixer">
590
<dt id="2to3fixer-zip">
591
<tt class="descname">zip</tt><a class="headerlink" href="#2to3fixer-zip" title="Permalink to this definition">¶</a></dt>
592
<dd><p>Wraps <a class="reference internal" href="functions.html#zip" title="zip"><tt class="xref py py-func docutils literal"><span class="pre">zip()</span></tt></a> usage in a <a class="reference internal" href="functions.html#list" title="list"><tt class="xref py py-class docutils literal"><span class="pre">list</span></tt></a> call. This is disabled when
593
<tt class="docutils literal"><span class="pre">from</span> <span class="pre">future_builtins</span> <span class="pre">import</span> <span class="pre">zip</span></tt> appears.</p>
597
<div class="section" id="module-lib2to3">
598
<span id="lib2to3-2to3-s-library"></span><h2>25.4.3. <a class="reference internal" href="#module-lib2to3" title="lib2to3: the 2to3 library"><tt class="xref py py-mod docutils literal"><span class="pre">lib2to3</span></tt></a> - 2to3’s library<a class="headerlink" href="#module-lib2to3" title="Permalink to this headline">¶</a></h2>
599
<div class="admonition note">
600
<p class="first admonition-title">Note</p>
601
<p class="last">The <a class="reference internal" href="#module-lib2to3" title="lib2to3: the 2to3 library"><tt class="xref py py-mod docutils literal"><span class="pre">lib2to3</span></tt></a> API should be considered unstable and may change
602
drastically in the future.</p>
611
<div class="sphinxsidebar">
612
<div class="sphinxsidebarwrapper">
613
<h3><a href="../contents.html">Table Of Contents</a></h3>
615
<li><a class="reference internal" href="#">25.4. 2to3 - Automated Python 2 to 3 code translation</a><ul>
616
<li><a class="reference internal" href="#using-2to3">25.4.1. Using 2to3</a></li>
617
<li><a class="reference internal" href="#fixers">25.4.2. Fixers</a></li>
618
<li><a class="reference internal" href="#module-lib2to3">25.4.3. <tt class="docutils literal"><span class="pre">lib2to3</span></tt> - 2to3’s library</a></li>
623
<h4>Previous topic</h4>
624
<p class="topless"><a href="unittest.html"
625
title="previous chapter">25.3. <tt class="docutils literal"><span class="pre">unittest</span></tt> — Unit testing framework</a></p>
627
<p class="topless"><a href="test.html"
628
title="next chapter">25.5. <tt class="docutils literal"><span class="pre">test</span></tt> — Regression tests package for Python</a></p>
630
<ul class="this-page-menu">
631
<li><a href="../bugs.html">Report a Bug</a></li>
632
<li><a href="../_sources/library/2to3.txt"
633
rel="nofollow">Show Source</a></li>
636
<div id="searchbox" style="display: none">
637
<h3>Quick search</h3>
638
<form class="search" action="../search.html" method="get">
639
<input type="text" name="q" />
640
<input type="submit" value="Go" />
641
<input type="hidden" name="check_keywords" value="yes" />
642
<input type="hidden" name="area" value="default" />
644
<p class="searchtip" style="font-size: 90%">
645
Enter search terms or a module, class or function name.
648
<script type="text/javascript">$('#searchbox').show(0);</script>
651
<div class="clearer"></div>
653
<div class="related">
656
<li class="right" style="margin-right: 10px">
657
<a href="../genindex.html" title="General Index"
660
<a href="../py-modindex.html" title="Python Module Index"
663
<a href="test.html" title="25.5. test — Regression tests package for Python"
666
<a href="unittest.html" title="25.3. unittest — Unit testing framework"
668
<li><img src="../_static/py.png" alt=""
669
style="vertical-align: middle; margin-top: -1px"/></li>
670
<li><a href="https://www.python.org/">Python</a> »</li>
672
<span class="version_switcher_placeholder">2.7.10</span>
673
<a href="../index.html">Documentation</a> »
676
<li><a href="index.html" >The Python Standard Library</a> »</li>
677
<li><a href="development.html" >25. Development Tools</a> »</li>
681
© <a href="../copyright.html">Copyright</a> 1990-2015, Python Software Foundation.
683
The Python Software Foundation is a non-profit corporation.
684
<a href="https://www.python.org/psf/donations/">Please donate.</a>
686
Last updated on May 23, 2015.
687
<a href="../bugs.html">Found a bug</a>?
689
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2.3.
b'\\ No newline at end of file'