diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index 36a1965..ac19f06 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -56,6 +56,7 @@ for (var i = arTables.length - 1; i >= 0; i--) {
print statement
unicode() global function
long data type
has_key() dictionary method
@@ -72,11 +73,11 @@ for (var i = arTables.length - 1; i >= 0; i--) {
filter() global function
map() global function
-reduce() global function (3.1+)
+reduce() global function (3.1+)
apply() global function
intern() global function
exec statement
-execfile statement (3.1+)
+execfile statement (3.1+)
repr literals (backticks)
try...except statement
raise statement
@@ -89,24 +90,23 @@ for (var i = arTables.length - 1; i >= 0; i--) {
next() iterator method
__nonzero__ special class attribute
-sys.maxint
-unicode() global function
callable() global function
zip() global function
StandardError() exception
types module constants
-isinstance global function (3.1+)
+isinstance() global function (3.1+)
basestring datatype
itertools module
sys.exc_type, sys.exc_value, sys.exc_traceback
os.getcwdu() function
set() literals
-buffer() global function
-set() literals (explicit)
+buffer() global function (explicit)
+unicode() global functionFIXME intro + +
| Notes | +Python 2 | +Python 3 | +
|---|---|---|
| ① | +unicode(anything) |
+str(anything) |
+
long data typePython 2 had separate int and long types for non-floating-point numbers. An int could not be any larger than sys.maxint, which varied by platform. Longs were defined by appending an L to the end of the number, and they could be, well, longer than ints. In Python 3, there is only one integer type, called int, which mostly behaves like the long type in Python 2.
@@ -740,11 +762,6 @@ except ImportError:
In Python 3, the reduce() function has been removed from the global namespace and placed in the functools module.
-
--☞ -
The version of
2to3that shipped with Python 3.0 would not fix thereduce()function automatically. The fix first appeared in the2to3script that shipped with Python 3.1. -
+
+☞ +
The version of
2to3that shipped with Python 3.0 would not fix thereduce()function automatically. The fix first appeared in the2to3script that shipped with Python 3.1. +
apply() global functionLike the old exec statement, the old execfile statement will execute strings as if they were Python code. Where exec took a string, execfile took a filename. In Python 3, the execfile statement has been eliminated. If you really need to take a file of Python code and execute it (but you're not willing to simply import it), you can accomplish the same thing by opening the file, reading its contents, calling the global compile() function to force the Python interpreter to compile the code, and then call the new exec() function.
-
--☞ -
The version of
2to3that shipped with Python 3.0 would not fix theexecfilestatement automatically. The fix first appeared in the2to3script that shipped with Python 3.1. -
+
+☞ +
The version of
2to3that shipped with Python 3.0 would not fix theexecfilestatement automatically. The fix first appeared in the2to3script that shipped with Python 3.1. +
repr literals (backticks)☞ -
You should never use a fallback to catch all exceptions when importing modules (or most other times), because it will also catch things like
KeyboardInterrupt(if the user pressed Ctrl-C to interrupt the program) and can make it more difficult to debug errors. +You should never use a fallback to catch all exceptions when importing modules (or most other times). Doing so will catch things like
KeyboardInterrupt(if the user pressed Ctrl-C to interrupt the program) and can make it more difficult to debug errors.
raise statementFIXME intro @@ -1382,11 +1400,6 @@ for an_iterator in a_sequence_of_iterators:
x = 12Lx = 12x = 0755x = 0o755sys.maxintunicode() global functionFIXME intro - -
| Notes | -Python 2 | -Python 3 | -
|---|---|---|
| ① | -unicode(anything) |
-str(anything) |
-
callable() global functionFIXME intro @@ -1540,55 +1530,43 @@ a_function(sys.maxsize)
types.StringTypebytestypes.DictTypedicttypes.IntTypeinttypes.LongTypeinttypes.ListTypelisttypes.NoneTypetype(None)-
isinstance global function (3.1+)isinstance() global function (3.1+)FIXME intro -
--☞ -
The version of
2to3that shipped with Python 3.0 would not fix these cases ofisinstance()automatically. The fix first appeared in the2to3script that shipped with Python 3.1. -
+☞ +
The version of
2to3that shipped with Python 3.0 would not fix these cases ofisinstance()automatically. The fix first appeared in the2to3script that shipped with Python 3.1. +
basestring datatypeisinstance(x, basestring)isinstance(x, str)
itertools module
[i for i in 1, 2][i for i in (1, 2)]
os.getcwdu() functionos.getcwdu()os.getcwd()
class Whip(Whipper):
+class C(Whipper):
__metaclass__ = PapayaMeta
-class Whip(Whipper, metaclass=PapayaMeta):
+class C(Whipper, metaclass=PapayaMeta):
pass
set() literalsset() literals (explicit)FIXME intro +
++☞ +
The
2to3script will not fixset()literals by default. To enable this fix, specify-f set_literalon the command line when you call2to3. +