mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
725b4dba86
--HG-- rename : dip2.html => dip2
1839 lines
38 KiB
HTML
1839 lines
38 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Porting code to Python 3 with 2to3 - Dive into Python 3</title>
|
|
<link rel="stylesheet" type="text/css" href="dip3.css">
|
|
<style type="text/css">
|
|
body{counter-reset:h1 19}
|
|
</style>
|
|
<script type="text/javascript">
|
|
window.onload = function() {
|
|
var arTables = document.getElementsByTagName('table');
|
|
for (var i = arTables.length - 1; i >= 0; i--) {
|
|
var elmTable = arTables[i];
|
|
var olNotes = document.getElementById("skip" + elmTable.id);
|
|
if (!olNotes) { continue; }
|
|
var arNotes = olNotes.getElementsByTagName('li');
|
|
var arTableRows = elmTable.getElementsByTagName('tr');
|
|
if (arNotes.length != arTableRows.length - 1) { continue; }
|
|
for (var j = arTableRows.length - 1; j >= 1; j--) {
|
|
var elmTableRow = arTableRows[j];
|
|
var elmNote = arNotes[j - 1];
|
|
elmTableRow._li = elmNote;
|
|
elmNote._tr = elmTableRow;
|
|
elmTableRow.addEventListener('mouseover', function() {
|
|
this.className = 'hover';
|
|
this._li.className = 'hover';
|
|
}, true);
|
|
elmNote.addEventListener('mouseover', function() {
|
|
this.className = 'hover';
|
|
this._tr.className = 'hover';
|
|
}, true);
|
|
elmTableRow.addEventListener('mouseout', function() {
|
|
this.className = '';
|
|
this._li.className = '';
|
|
}, true);
|
|
elmNote.addEventListener('mouseout', function() {
|
|
this.className = '';
|
|
this._tr.className = '';
|
|
}, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<h1>Porting code to Python 3 with <code>2to3</code></h1>
|
|
|
|
<ol class="toc">
|
|
<li><a href="#divingin">Diving in</a></li>
|
|
<li><a href="#print"><code>print</code> statement</a></li>
|
|
<li><a href="#ne"><> comparison</a></li>
|
|
<li><a href="#has_key"><code>has_key()</code> dictionary method</a></li>
|
|
<li><a href="#dict">Dictionary methods</a></li>
|
|
<li><a href="#imports">Modules that have been renamed or reorganized</a></li>
|
|
<li><a href="#filter"><code>filter()</code> global function</a></li>
|
|
<li><a href="#map"><code>map()</code> global function</a></li>
|
|
<li><a href="#apply"><code>apply()</code> global function</a></li>
|
|
<li><a href="#intern"><code>intern()</code> global function</a></li>
|
|
<li><a href="#exec"><code>exec</code> statement</a></li>
|
|
<li><a href="#repr"><code>repr</code> literals (backticks)</a></li>
|
|
<li><a href="#except"><code>try...except</code> statement</a></li>
|
|
<li><a href="#raise"><code>raise</code> statement</a></li>
|
|
<li><a href="#throw"><code>throw</code> statement</a></li>
|
|
<li><a href="#long"><code>long</code> data type</a></li>
|
|
<li><a href="#xrange"><code>xrange()</code> global function</a></li>
|
|
<li><a href="#raw_input"><code>raw_input()</code> and <code>input()</code> global functions</a></li>
|
|
<li><a href="#funcattrs"><code>func_*</code> function attributes</a></li>
|
|
<li><a href="#xreadlines"><code>xreadlines()</code> I/O method</a></li>
|
|
<li><a href="#tuple_params"><code>lambda</code> functions with multiple parameters</a></li>
|
|
<li><a href="#methodattrs"><code>__class__</code> special class attribute</a></li>
|
|
<li><a href="#next"><code>next()</code> iterator method</a></li>
|
|
<li><a href="#nonzero"><code>__nonzero__</code> special class attribute</a></li>
|
|
<li><a href="#numliterals">Number literals</a></li>
|
|
<li><a href="#renames"><code>sys.maxint</code></a></li>
|
|
<li><a href="#unicode"><code>unicode()</code> global function</a></li>
|
|
<li><a href="#unicodeliteral">Unicode string literals</a></li>
|
|
<li><a href="#callable"><code>callable()</code> global function</a></li>
|
|
<li><a href="#zip"><code>zip()</code> global function</a></li>
|
|
<li><a href="#standarderror"><code>StandardError()</code> exception</a></li>
|
|
<li><a href="#types"><code class="filename">types</code> module constants</a></li>
|
|
<li><a href="#basestring"><code>basestring</code> datatype</a></li>
|
|
<li><a href="#itertools"><code class="filename">itertools</code> module</a></li>
|
|
<li><a href="#import">Relative imports</a></li>
|
|
<li><a href="#sys_exc"><code>sys.exc_type</code>, <code>sys.exc_value</code>, <code>sys.exc_traceback</code></a></li>
|
|
<li><a href="#paren">List comprehensions over tuples</a></li>
|
|
<li><a href="#getcwdu"><code>os.getcwdu()</code> function</a></li>
|
|
<li><a href="#metaclass">Metaclasses</a></li>
|
|
<li><a href="#set_literal"><code>set()</code> literals</a></li>
|
|
<li><a href="#buffer"><code>buffer()</code> global function</a></li>
|
|
<li><a href="#wscomma">Whitespace around commas</a></li>
|
|
<li><a href="#idioms">Common idioms</a></li>
|
|
</ol>
|
|
|
|
<section>
|
|
<h2 id="divingin">Diving in</h2>
|
|
|
|
<p class="fancy">FIXME intro</p>
|
|
|
|
<p>...</p>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="print"><code>print</code> statement</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareprint">skip over this table</a></p>
|
|
<table id="compareprint">
|
|
<tr>
|
|
<th class="notes">Notes</th>
|
|
<th class="python2">Python 2</th>
|
|
<th class="python3">Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>print</code></td>
|
|
<td><code>print()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>print 1</code></td>
|
|
<td><code>print(1)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>print 1, 2</code></td>
|
|
<td><code>print(1, 2)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>print 1, 2,</code></td>
|
|
<td><code>print(1, 2, end=' ')</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><code>print >>sys.stderr, 1, 2, 3</code></td>
|
|
<td><code>print(1, 2, 3, file=sys.stderr)</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareprint">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="ne"><> comparison</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparene">skip over this table</a></p>
|
|
<table id="comparene">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>if x <> y:</code></td>
|
|
<td><code>if x != y:</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>if x <> y <> z:</code></td>
|
|
<td><code>if x != y != z:</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparene">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="has_key"><code>has_key()</code> dictionary method</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparehas_key">skip over this table</a></p>
|
|
<table id="comparehas_key">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>aDictionary.has_key("PapayaWhip")</code></td>
|
|
<td><code>"PapayaWhip" in aDictionary</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th >
|
|
<td><code>aDictionary.has_key(x) or aDictionary.has_key(y)</code></td>
|
|
<td><code>x in aDictionary or y in aDictionary</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>aDictionary.has_key(x + y)</code></td>
|
|
<td><code>(x + y) in aDictionary</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>x + aDictionary.has_key(y)</code></td>
|
|
<td><code>x + (y in aDictionary)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><code>aDictionary.has_key(x or y)</code></td>
|
|
<td><code>(x or y) in aDictionary</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparehas_key">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="dict">Dictionary methods</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparedict">skip over this table</a></p>
|
|
<table id="comparedict">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>aDictionary.keys()</code></td>
|
|
<td><code>list(aDictionary.keys())</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>aDictionary.items()</code></td>
|
|
<td><code>list(aDictionary.items())</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>aDictionary.iterkeys()</code></td>
|
|
<td><code>iter(aDictionary.keys())</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>[i for i in aDictionary.iterkeys()]</code></td>
|
|
<td><code>[i for i in aDictionary.keys()]</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><code>min(aDictionary.keys())</code></td>
|
|
<td><i>no change</i></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparedict">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
<!--
|
|
5. consuming_calls = set(["sorted", "list", "set", "any", "all", "tuple", "sum",
|
|
"min", "max"])
|
|
-->
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="imports">Modules that have been renamed or reorganized</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
<p><a class="skip" href="#skipcompareimports">skip over this table</a></p>
|
|
<table id="compareimports">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><pre><code>import StringIO
|
|
import cStringIO</code></pre></td>
|
|
<td><code>import io</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>import cPickle</code></td>
|
|
<td><code>import pickle</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>import __builtin__</code></td>
|
|
<td><code>import builtins</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>import copy_reg</code></td>
|
|
<td><code>import copyreg</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><code>import Queue</code></td>
|
|
<td><code>import queue</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑥</th>
|
|
<td><code>import SocketServer</code></td>
|
|
<td><code>import socketserver</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑦</th>
|
|
<td><code>import ConfigParser</code></td>
|
|
<td><code>import configparser</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑧</th>
|
|
<td><code>import repr</code></td>
|
|
<td><code>import reprlib</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑨</th>
|
|
<td><code>import commands</code></td>
|
|
<td><code>import subprocess</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareimports">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
<p><a class="skip" href="#skipcompareimportdbm">skip over this table</a></p>
|
|
<table id="compareimportdbm">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>import dbm</code></td>
|
|
<td><code>import dbm.ndbm</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>import gdbm</code></td>
|
|
<td><code>import dbm.gnu</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>import dbhash</code></td>
|
|
<td><code>import dbm.bsd</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>import dumbdbm</code></td>
|
|
<td><code>import dbm.dumb</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><pre><code>import anydbm
|
|
import whichdb</code></pre></td>
|
|
<td><code>import dbm</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareimportdbm">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
<p><a class="skip" href="#skipcompareimportxmlrpc">skip over this table</a></p>
|
|
<table id="compareimportxmlrpc">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>import xmlrpclib</code></td>
|
|
<td><code>import xmlrpc.client</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><pre><code>import DocXMLRPCServer
|
|
import SimpleXMLRPCServer</code></pre></td>
|
|
<td><code>import xmlrpc.server</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareimportxmlrpc">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
<p><a class="skip" href="#skipcompareimporthttp">skip over this table</a></p>
|
|
<table id="compareimporthttp">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>import httplib</code></td>
|
|
<td><code>import http.client</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>import Cookie</code></td>
|
|
<td><code>import http.cookies</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>import cookielib</code></td>
|
|
<td><code>import http.cookiejar</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><pre><code>import BaseHTTPServer
|
|
import SimpleHTTPServer
|
|
import CGIHttpServer</code></pre></td>
|
|
<td><code>import http.server</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareimporthttp">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
<p><a class="skip" href="#skipcompareimporturllib">skip over this table</a></p>
|
|
<table id="compareimporturllib">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>import urllib</code></td>
|
|
<td><code>import urllib.request, urllib.parse, urllib.error</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>import urllib2</code></td>
|
|
<td><code>import urllib.request, urllib.error</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>import urlparse</code></td>
|
|
<td><code>import urllib.parse</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>import robotparser</code></td>
|
|
<td><code>import urllib.robotparser</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><pre><code>from urllib import FancyURLOpener
|
|
from urllib import urlencode</code></pre></td>
|
|
<td><pre><code>from urllib.request import FancyURLOpener
|
|
from urllib.parse import urlencode</code></pre></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑥</th>
|
|
<td><pre><code>from urllib2 import Request
|
|
from urllib2 import HTTPError</code></pre></td>
|
|
<td><pre><code>from urllib.request import Request
|
|
from urllib.error import HTTPError</code></pre></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareimporturllib">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="filter"><code>filter()</code> global function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparefilter">skip over this table</a></p>
|
|
<table id="comparefilter">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>filter(aFunction, aList)</code></td>
|
|
<td><code>list(filter(aFunction, aList))</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>list(filter(aFunction, aList))</code></td>
|
|
<td><i>no change</i></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>filter(None, aList)</code></td>
|
|
<td><code>[i for i in aList if i]</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>for i in filter(None, aList)</code></td>
|
|
<td><i>no change</i></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><code>[i for i in filter(aFunction, aList)]</code></td>
|
|
<td><i>no change</i></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparefilter">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="map"><code>map()</code> global function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparemap">skip over this table</a></p>
|
|
<table id="comparemap">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>map(aFunction, 'PapayaWhip')</code></td>
|
|
<td><code>list(map(aFunction, 'PapayaWhip'))</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>map(None, 'PapayaWhip')</code></td>
|
|
<td><code>list('PapayaWhip')</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>map(lambda x: x+1, range(42))</code></td>
|
|
<td><code>[x+1 for x in range(42)]</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>for i in map(aFunction, aList):</code></td>
|
|
<td><i>unchanged</i></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><code>[i for i in map(aFunction, aList)]</code></td>
|
|
<td><i>unchanged</i></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparemap">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="apply"><code>apply()</code> global function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareapply">skip over this table</a></p>
|
|
<table id="compareapply">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>apply(aFunction, args)</code></td>
|
|
<td><code>aFunction(*args)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>apply(aFunction, args, kwds)</code></td>
|
|
<td><code>aFunction(*args, **kwds)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>apply(aFunction, args + z)</code></td>
|
|
<td><code>aFunction(*args + z)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>apply(aModule.aFunction, args)</code></td>
|
|
<td><code>aModule.aFunction(*args)</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareapply">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="intern"><code>intern()</code> global function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareintern">skip over this table</a></p>
|
|
<table id="compareintern">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>intern(aString)</code></td>
|
|
<td><code>sys.intern(aString)</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareintern">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="exec"><code>exec</code> statement</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareexec">skip over this table</a></p>
|
|
<table id="compareexec">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>exec codeString</code></td>
|
|
<td><code>exec(codeString)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>exec codeString in aGlobalNamespace</code></td>
|
|
<td><code>exec(codeString, aGlobalNamespace)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>exec codeString in aGlobalNamespace, aLocalNamespace</code></td>
|
|
<td><code>exec(codeString, aGlobalNamespace, aLocalNamespace)</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareexec">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="repr"><code>repr</code> literals (backticks)</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparerepr">skip over this table</a></p>
|
|
<table id="comparerepr">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>`x`</code></td>
|
|
<td><code>repr(x)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>`1 + 2`</code></td>
|
|
<td><code>repr(1 + 2)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>`"PapayaWhip" + `2``</code></td>
|
|
<td><code>repr("PapayaWhip" + repr(2))</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparerepr">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="except"><code>try...except</code> statement</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareexcept">skip over this table</a></p>
|
|
<table id="compareexcept">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><pre><code>try:
|
|
import mymodule
|
|
except ImportError, e
|
|
pass</code></pre></td>
|
|
<td><pre><code>try:
|
|
import mymodule
|
|
except ImportError as e:
|
|
pass</code></pre></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><pre><code>try:
|
|
import mymodule
|
|
except (RuntimeError, ImportError), e
|
|
pass</code></pre></td>
|
|
<td><pre><code>try:
|
|
import mymodule
|
|
except (RuntimeError, ImportError) as e:
|
|
pass</code></pre></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><pre><code>try:
|
|
import mymodule
|
|
except ImportError:
|
|
pass</code></pre></td>
|
|
<td><i>unchanged</i></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><pre><code>try:
|
|
import mymodule
|
|
except:
|
|
pass</code></pre></td>
|
|
<td><i>unchanged</i></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareexcept">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="raise"><code>raise</code> statement</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareraise">skip over this table</a></p>
|
|
<table id="compareraise">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>raise MyException, "error message"</code></td>
|
|
<td><code>raise MyException("error message")</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>raise MyException, "error message", aTraceback</code></td>
|
|
<td><code>raise MyException("error message").with_traceback(aTraceback)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>raise "error message"</code></td>
|
|
<td><i>unsupported</i></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareraise">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="throw"><code>throw</code> statement</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparethrow">skip over this table</a></p>
|
|
<table id="comparethrow">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>aGenerator.throw(MyException)</code></td>
|
|
<td><i>unchanged</i></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>aGenerator.throw(MyException, "error message")</code></td>
|
|
<td><code>aGenerator.throw(MyException("error message"))</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>aGenerator.throw("error message")</code></td>
|
|
<td><i>unsupported</i></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparethrow">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="long"><code>long</code> data type</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparelong">skip over this table</a></p>
|
|
<table id="comparelong">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>x = 1000000000000L</code></td>
|
|
<td><code>x = 1000000000000</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>x = 0xFFFFFFFFFFFFL</code></td>
|
|
<td><code>x = 0xFFFFFFFFFFFF</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>long(x)</code></td>
|
|
<td><code>int(x)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>type(x) is long</code></td>
|
|
<td><code>type(x) is int</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><code>isinstance(x, long)</code></td>
|
|
<td><code>isinstance(x, int)</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparelong">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="xrange"><code>xrange()</code> global function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparexrange">skip over this table</a></p>
|
|
<table id="comparexrange">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>xrange(10)</code></td>
|
|
<td><code>range(10)</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>aList = range(10)</code></td>
|
|
<td><code>aList = list(range(10))</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>[i for i in xrange(10)]</code></td>
|
|
<td><code>[i for i in range(10)]</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>for i in range(10):</code></td>
|
|
<td><i>unchanged</i></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><code>sum(range(10))</code></td>
|
|
<td><i>unchanged</i></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparexrange">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="raw_input"><code>raw_input()</code> and <code>input()</code> global functions</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareraw_input">skip over this table</a></p>
|
|
<table id="compareraw_input">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>raw_input()</code></td>
|
|
<td><code>input()</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>raw_input("prompt")</code></td>
|
|
<td><code>input("prompt")</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>input()</code></td>
|
|
<td><code>eval(input())</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>input("prompt")</code></td>
|
|
<td><code>eval(input("prompt"))</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareraw_input">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="funcattrs"><code>func_*</code> function attributes</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparefuncattrs">skip over this table</a></p>
|
|
<table id="comparefuncattrs">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>aFunction.func_closure</code></td>
|
|
<td><code>aFunction.__closure__</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>aFunction.func_doc</code></td>
|
|
<td><code>aFunction.__doc__</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>③</th>
|
|
<td><code>aFunction.func_name</code></td>
|
|
<td><code>aFunction.__name__</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>④</th>
|
|
<td><code>aFunction.func_defaults</code></td>
|
|
<td><code>aFunction.__defaults__</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑤</th>
|
|
<td><code>aFunction.func_code</code></td>
|
|
<td><code>aFunction.__code__</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑥</th>
|
|
<td><code>aFunction.func_globals</code></td>
|
|
<td><code>aFunction.__globals__</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>⑦</th>
|
|
<td><code>aFunction.func_dict</code></td>
|
|
<td><code>aFunction.__dict__</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparefuncattrs">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="xreadlines"><code>xreadlines()</code> I/O method</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparexreadlines">skip over this table</a></p>
|
|
<table id="comparexreadlines">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>for line in aFile.xreadlines():</code></td>
|
|
<td><code>for line in aFile:</code></td>
|
|
</tr>
|
|
<tr>
|
|
<th>②</th>
|
|
<td><code>for line in aFile.xreadlines(5):</code></td>
|
|
<td><i>unchanged</i></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparexreadlines">
|
|
<li>...</li>
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="tuple_params"><code>lambda</code> functions with multiple parameters</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparetuple_params">skip over this table</a></p>
|
|
<table id="comparetuple_params">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparetuple_params">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="methodattrs"><code>__class__</code> special class attribute</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparemethodattrs">skip over this table</a></p>
|
|
<table id="comparemethodattrs">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparemethodattrs">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="next"><code>next()</code> iterator method</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparenext">skip over this table</a></p>
|
|
<table id="comparenext">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparenext">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="nonzero"><code>__nonzero__</code> special class attribute</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparenonzero">skip over this table</a></p>
|
|
<table id="comparenonzero">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparenonzero">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="numliterals">Number literals</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparenumliterals">skip over this table</a></p>
|
|
<table id="comparenumliterals">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparenumliterals">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="renames"><code>sys.maxint</code></h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparerenames">skip over this table</a></p>
|
|
<table id="comparerenames">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparerenames">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="unicode"><code>unicode()</code> global function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareunicode">skip over this table</a></p>
|
|
<table id="compareunicode">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareunicode">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="unicodeliteral">Unicode string literals</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareunicodeliteral">skip over this table</a></p>
|
|
<table id="compareunicodeliteral">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareunicodeliteral">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="callable"><code>callable()</code> global function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparecallable">skip over this table</a></p>
|
|
<table id="comparecallable">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparecallable">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="zip"><code>zip()</code> global function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparezip">skip over this table</a></p>
|
|
<table id="comparezip">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparezip">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="standarderror"><code>StandardError()</code> exception</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparestandarderror">skip over this table</a></p>
|
|
<table id="comparestandarderror">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparestandarderror">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="types"><code class="filename">types</code> module constants</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparetypes">skip over this table</a></p>
|
|
<table id="comparetypes">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparetypes">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="basestring"><code>basestring</code> datatype</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparebasestring">skip over this table</a></p>
|
|
<table id="comparebasestring">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparebasestring">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="itertools"><code class="filename">itertools</code> module</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
<p>this includes fixer_itertools, fixer_itertools_imports
|
|
<table id="compareitertools">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareitertools">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="import">Relative imports</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareimport">skip over this table</a></p>
|
|
<table id="compareimport">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareimport">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="sys_exc"><code>sys.exc_type</code>, <code>sys.exc_value</code>, <code>sys.exc_traceback</code></h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparesys_exc">skip over this table</a></p>
|
|
<table id="comparesys_exc">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparesys_exc">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="paren">List comprehensions over tuples</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareparen">skip over this table</a></p>
|
|
<table id="compareparen">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareparen">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="getcwdu"><code>os.getcwdu()</code> function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparegetcwdu">skip over this table</a></p>
|
|
<table id="comparegetcwdu">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparegetcwdu">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="metaclass">Metaclasses</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparemetaclass">skip over this table</a></p>
|
|
<table id="comparemetaclass">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparemetaclass">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="set_literal"><code>set()</code> literals</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareset_literal">skip over this table</a></p>
|
|
<table id="compareset_literal">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareset_literal">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="buffer"><code>buffer()</code> global function</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparebuffer">skip over this table</a></p>
|
|
<table id="comparebuffer">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparebuffer">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="wscomma">Whitespace around commas</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcomparewscomma">skip over this table</a></p>
|
|
<table id="comparewscomma">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcomparewscomma">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
<h2 id="idioms">Common idioms</h2>
|
|
|
|
<p>FIXME intro</p>
|
|
|
|
<p><a class="skip" href="#skipcompareidioms">skip over this table</a></p>
|
|
<table id="compareidioms">
|
|
<tr>
|
|
<th>Notes</th>
|
|
<th>Python 2</th>
|
|
<th>Python 3</th>
|
|
</tr>
|
|
<tr>
|
|
<th>①</th>
|
|
<td><code>FIXME</code></td>
|
|
<td><code>FIXME</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<ol id="skipcompareidioms">
|
|
<li>...</li>
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
<footer>
|
|
<p class="c">© 2001-4, 2009 Mark Pilgrim, <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">CC-BY-3.0</a></p>
|
|
</footer>
|
|
|
|
</body>
|
|
</html>
|
|
|
|
<!--
|
|
# Lib/lib2to3/tests/test_fixers.py
|
|
|
|
- <>
|
|
- has_key
|
|
- apply()
|
|
- intern()
|
|
- print
|
|
- exec()
|
|
- repr()
|
|
- except
|
|
- raise
|
|
- throw
|
|
- long()
|
|
- dict()
|
|
- xrange()
|
|
- raw_input()
|
|
- input()
|
|
- func_* attributes
|
|
- xreadlines()
|
|
- imports of modules that have been renamed:
|
|
# Lib/lib2to3/fixes/fix_imports.py
|
|
MAPPING = {'StringIO': 'io',
|
|
'cStringIO': 'io',
|
|
'cPickle': 'pickle',
|
|
'__builtin__' : 'builtins',
|
|
'copy_reg': 'copyreg',
|
|
'Queue': 'queue',
|
|
'SocketServer': 'socketserver',
|
|
'ConfigParser': 'configparser',
|
|
'repr': 'reprlib',
|
|
'FileDialog': 'tkinter.filedialog',
|
|
'tkFileDialog': 'tkinter.filedialog',
|
|
'SimpleDialog': 'tkinter.simpledialog',
|
|
'tkSimpleDialog': 'tkinter.simpledialog',
|
|
'tkColorChooser': 'tkinter.colorchooser',
|
|
'tkCommonDialog': 'tkinter.commondialog',
|
|
'Dialog': 'tkinter.dialog',
|
|
'Tkdnd': 'tkinter.dnd',
|
|
'tkFont': 'tkinter.font',
|
|
'tkMessageBox': 'tkinter.messagebox',
|
|
'ScrolledText': 'tkinter.scrolledtext',
|
|
'turtle': 'tkinter.turtle',
|
|
'Tkconstants': 'tkinter.constants',
|
|
'Tix': 'tkinter.tix',
|
|
'Tkinter': 'tkinter',
|
|
'markupbase': '_markupbase',
|
|
'_winreg': 'winreg',
|
|
'thread': '_thread',
|
|
'dummy_thread': '_dummy_thread',
|
|
# anydbm and whichdb are handled by fix_imports2
|
|
'dbhash': 'dbm.bsd',
|
|
'dumbdbm': 'dbm.dumb',
|
|
'dbm': 'dbm.ndbm',
|
|
'gdbm': 'dbm.gnu',
|
|
'xmlrpclib': 'xmlrpc.client',
|
|
'DocXMLRPCServer': 'xmlrpc.server',
|
|
'SimpleXMLRPCServer': 'xmlrpc.server',
|
|
'httplib': 'http.client',
|
|
'Cookie': 'http.cookies',
|
|
'cookielib': 'http.cookiejar',
|
|
'BaseHTTPServer': 'http.server',
|
|
'SimpleHTTPServer': 'http.server',
|
|
'CGIHTTPServer': 'http.server',
|
|
#'test.test_support': 'test.support',
|
|
'commands': 'subprocess',
|
|
'UserString' : 'collections',
|
|
'UserList' : 'collections',
|
|
'urlparse' : 'urllib.parse',
|
|
'robotparser' : 'urllib.robotparser',
|
|
}
|
|
- imports of urllib/urllib2
|
|
# Lib/lib2to3/fixes/fix_urllib.py
|
|
MAPPING = {'urllib': [
|
|
('urllib.request',
|
|
['URLOpener', 'FancyURLOpener', 'urlretrieve',
|
|
'_urlopener', 'urlcleanup']),
|
|
('urllib.parse',
|
|
['quote', 'quote_plus', 'unquote', 'unquote_plus',
|
|
'urlencode', 'pahtname2url', 'url2pathname']),
|
|
('urllib.error',
|
|
['ContentTooShortError'])],
|
|
'urllib2' : [
|
|
('urllib.request',
|
|
['urlopen', 'install_opener', 'build_opener',
|
|
'Request', 'OpenerDirector', 'BaseHandler',
|
|
'HTTPDefaultErrorHandler', 'HTTPRedirectHandler',
|
|
'HTTPCookieProcessor', 'ProxyHandler',
|
|
'HTTPPasswordMgr',
|
|
'HTTPPasswordMgrWithDefaultRealm',
|
|
'AbstractBasicAuthHandler',
|
|
'HTTPBasicAuthHandler', 'ProxyBasicAuthHandler',
|
|
'AbstractDigestAuthHandler',
|
|
'HTTPDigestAuthHander', 'ProxyDigestAuthHandler',
|
|
'HTTPHandler', 'HTTPSHandler', 'FileHandler',
|
|
'FTPHandler', 'CacheFTPHandler',
|
|
'UnknownHandler']),
|
|
('urllib.error',
|
|
['URLError', 'HTTPError'])],
|
|
}
|
|
- tuple params (?!??!)
|
|
- __class__ special attribute
|
|
- __nonzero__ special method
|
|
- next()
|
|
- sys.maxint
|
|
- number literals
|
|
- Unicode string literals
|
|
- callable()
|
|
- filter()
|
|
- map()
|
|
- zip()
|
|
- StandardError()
|
|
- types module
|
|
- basestring type
|
|
- itertools functions
|
|
- itertools imports
|
|
- relative imports
|
|
- sys.exc_type, sys.exc_value, sys.exc_traceback
|
|
- list comprehensions over tuples
|
|
- os.getcwdu()
|
|
- metaclasses
|
|
- set literals (EXPLICIT)
|
|
- whitespace around commas (EXPLICIT)
|
|
- buffer() (EXPLICIT)
|
|
- common idioms (EXPLICIT)
|
|
- while 1
|
|
- type(X) == T, type(X) != T
|
|
- type(X) is T, type(X) is not T
|
|
- T is type(X), T is not type(X)
|
|
- list.sort()
|
|
-->
|