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--) {
  • Diving in
  • print statement
  • Unicode string literals +
  • unicode() global function
  • long data type
  • <> comparison
  • has_key() dictionary method @@ -72,11 +73,11 @@ for (var i = arTables.length - 1; i >= 0; i--) {
  • Relative imports within a package
  • 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--) {
  • Special method attributes
  • next() iterator method
  • __nonzero__ special class attribute -
  • Number literals +
  • Octal literals
  • 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
  • List comprehensions over tuples
  • os.getcwdu() function
  • Metaclasses -
  • set() literals -
  • buffer() global function -
  • Whitespace around commas -
  • Common idioms +
  • set() literals (explicit) +
  • buffer() global function (explicit) +
  • Whitespace around commas (explicit) +
  • Common idioms (explicit)

    Diving in

    @@ -187,6 +187,28 @@ for (var i = arTables.length - 1; i >= 0; i--) {
  • Unicode "raw" strings (in which Python does not auto-escape backslashes) are converted to raw strings. In Python 3, "raw" strings are also Unicode. +

    unicode() global function

    + +

    FIXME intro + +

    skip over this table + + + + + + + + + + + +
    NotesPython 2Python 3
    unicode(anything)str(anything)
    + +

      +
    1. ... +
    +

    long data type

    Python 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 2to3 that shipped with Python 3.0 would not fix the reduce() function automatically. The fix first appeared in the 2to3 script that shipped with Python 3.1. -

    -

    skip over this table @@ -760,7 +777,10 @@ reduce(a, b, c)
    -

    +

    +

    ☞ +

    The version of 2to3 that shipped with Python 3.0 would not fix the reduce() function automatically. The fix first appeared in the 2to3 script that shipped with Python 3.1. +

    apply() global function

    @@ -860,11 +880,6 @@ reduce(a, b, c)

    Like 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 2to3 that shipped with Python 3.0 would not fix the execfile statement automatically. The fix first appeared in the 2to3 script that shipped with Python 3.1. -

    -

    skip over this table @@ -879,7 +894,10 @@ reduce(a, b, c)
    -

    +

    +

    ☞ +

    The version of 2to3 that shipped with Python 3.0 would not fix the execfile statement automatically. The fix first appeared in the 2to3 script that shipped with Python 3.1. +

    repr literals (backticks)

    @@ -969,7 +987,7 @@ except:

    ☞ -

    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 statement

    @@ -1370,7 +1388,7 @@ for an_iterator in a_sequence_of_iterators:
  • ... -

    Number literals

    +

    Octal literals

    FIXME intro @@ -1382,11 +1400,6 @@ for an_iterator in a_sequence_of_iterators: Python 3 -① -x = 12L -x = 12 - - ② x = 0755 x = 0o755 @@ -1395,7 +1408,6 @@ for an_iterator in a_sequence_of_iterators:

    1. ... -
    2. ...

    sys.maxint

    @@ -1428,28 +1440,6 @@ a_function(sys.maxsize)
  • ... -

    unicode() global function

    - -

    FIXME intro - -

    skip over this table - - - - - - - - - - - -
    NotesPython 2Python 3
    unicode(anything)str(anything)
    - -

      -
    1. ... -
    -

    callable() global function

    FIXME intro @@ -1540,55 +1530,43 @@ a_function(sys.maxsize) Python 3 -① + types.StringType bytes -② + types.DictType dict -③ + types.IntType int -④ + types.LongType int -⑤ + types.ListType list -⑥ + types.NoneType type(None) -

      -
    1. ... -
    2. ... -
    3. ... -
    4. ... -
    5. ... -
    6. ... -
    +

    -

    isinstance global function (3.1+)

    +

    isinstance() global function (3.1+)

    FIXME intro -

    -

    ☞ -

    The version of 2to3 that shipped with Python 3.0 would not fix these cases of isinstance() automatically. The fix first appeared in the 2to3 script that shipped with Python 3.1. -

    -

    skip over this table @@ -1603,9 +1581,10 @@ a_function(sys.maxsize)
    -

      -
    1. ... -
    +
    +

    ☞ +

    The version of 2to3 that shipped with Python 3.0 would not fix these cases of isinstance() automatically. The fix first appeared in the 2to3 script that shipped with Python 3.1. +

    basestring datatype

    @@ -1619,15 +1598,13 @@ a_function(sys.maxsize) Python 3 -① + isinstance(x, basestring) isinstance(x, str) -
      -
    1. ... -
    +

    itertools module

    @@ -1702,11 +1679,7 @@ a_function(sys.maxsize) -
      -
    1. ... -
    2. ... -
    3. ... -
    +

    List comprehensions over tuples

    @@ -1720,15 +1693,13 @@ a_function(sys.maxsize) Python 3 -① + [i for i in 1, 2] [i for i in (1, 2)] -
      -
    1. ... -
    +

    os.getcwdu() function

    @@ -1742,15 +1713,13 @@ a_function(sys.maxsize) Python 3 -① + os.getcwdu() os.getcwd() -
      -
    1. ... -
    +

    Metaclasses

    @@ -1772,9 +1741,9 @@ a_function(sys.maxsize) ② -
    class Whip(Whipper):
    +
    class C(Whipper):
         __metaclass__ = PapayaMeta
    -
    class Whip(Whipper, metaclass=PapayaMeta):
    +
    class C(Whipper, metaclass=PapayaMeta):
         pass
    @@ -1784,10 +1753,15 @@ a_function(sys.maxsize)
  • ... -

    set() literals

    +

    set() literals (explicit)

    FIXME intro +

    +

    ☞ +

    The 2to3 script will not fix set() literals by default. To enable this fix, specify -f set_literal on the command line when you call 2to3. +

    +

    skip over this table @@ -1818,10 +1792,15 @@ a_function(sys.maxsize)
  • ... -

    buffer() global function

    +

    buffer() global function (explicit)

    FIXME intro +

    +

    ☞ +

    The 2to3 script will not fix the buffer() function by default. To enable this fix, specify -f buffer on the command line when you call 2to3. +

    +

    skip over this table

  • @@ -1840,10 +1819,15 @@ a_function(sys.maxsize)
  • ... -

    Whitespace around commas

    +

    Whitespace around commas (explicit)

    FIXME intro +

    +

    ☞ +

    The 2to3 script will not fix whitespace around commas by default. To enable this fix, specify -f wscomma on the command line when you call 2to3. +

    +

    skip over this table

  • @@ -1868,10 +1852,15 @@ a_function(sys.maxsize)
  • ... -

    Common idioms

    +

    Common idioms (explicit)

    FIXME intro +

    +

    ☞ +

    The 2to3 script will not fix common idioms by default. To enable this fix, specify -f idioms on the command line when you call 2to3. +

    +

    skip over this table