From 00757566f54b2d6e42e2e51e9ca16781456f82a7 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Thu, 16 Jul 2009 23:15:05 -0400 Subject: [PATCH] copious links back to previous chapters --- porting-code-to-python-3-with-2to3.html | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index 19bba43..e86066c 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -38,7 +38,7 @@ td pre{padding:0;border:0}

print statement

-

In Python 2, print was a statement. Whatever you wanted to print simply followed the print keyword. In Python 3, print() is a function — whatever you want to print is passed to print() like any other function. +

In Python 2, print was a statement. Whatever you wanted to print simply followed the print keyword. In Python 3, print() is a function. Whatever you want to print, pass it to print() like any other function.
Notes @@ -71,7 +71,7 @@ td pre{padding:0;border:0}

Unicode string literals

-

Python 2 had two string types: Unicode strings and non-Unicode strings. Python 3 has one string type: Unicode strings. +

Python 2 had two string types: Unicode strings and non-Unicode strings. Python 3 has one string type: Unicode strings.
Notes @@ -92,7 +92,7 @@ td pre{padding:0;border:0}

unicode() global function

-

Python 2 had two global functions to coerce objects into strings: unicode() to coerce them into Unicode strings, and str() to coerce them into non-Unicode strings. Python 3 has only one string type, Unicode strings, so the str() function is all you need. (The unicode() function no longer exists.) +

Python 2 had two global functions to coerce objects into strings: unicode() to coerce them into Unicode strings, and str() to coerce them into non-Unicode strings. Python 3 has only one string type, Unicode strings, so the str() function is all you need. (The unicode() function no longer exists.)
Notes @@ -105,7 +105,7 @@ td pre{padding:0;border:0}

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. Since there are no longer two types, there is no need for special syntax to distinguish them. +

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. Since there are no longer two types, there is no need for special syntax to distinguish them.

Further reading: PEP 237: Unifying Long Integers and Integers. @@ -160,7 +160,7 @@ td pre{padding:0;border:0}

has_key() dictionary method

-

In Python 2, dictionaries had a has_key() method to test whether the dictionary had a certain key. In Python 3, this method no longer exists. Instead, you need to use the in operator. +

In Python 2, dictionaries had a has_key() method to test whether the dictionary had a certain key. In Python 3, this method no longer exists. Instead, you need to use the in operator.

Notes @@ -443,7 +443,7 @@ except ImportError:

next() iterator method

-

In Python 2, iterators had a next() method which returned the next item in the sequence. That’s still true in Python 3, but there is now also a global next() function that takes an iterator as an argument. +

In Python 2, iterators had a next() method which returned the next item in the sequence. That’s still true in Python 3, but there is now also a global next() function that takes an iterator as an argument.
Notes @@ -667,7 +667,7 @@ reduce(a, b, c)

try...except statement

-

The syntax for catching exceptions has changed slightly between Python 2 and Python 3. +

The syntax for catching exceptions has changed slightly between Python 2 and Python 3.
Notes @@ -718,7 +718,7 @@ except:

raise statement

-

The syntax for raising your own exceptions has changed slightly between Python 2 and Python 3. +

The syntax for raising your own exceptions has changed slightly between Python 2 and Python 3.
Notes @@ -1152,7 +1152,7 @@ except:

itertools module

-

Python 2.3 introduced the itertools module, which defined variants of the global zip(), map(), and filter() functions that returned iterators instead of lists. In Python 3, those global functions return iterators, so those functions in the itertools module have been eliminated. +

Python 2.3 introduced the itertools module, which defined variants of the global zip(), map(), and filter() functions that returned iterators instead of lists. In Python 3, those global functions return iterators, so those functions in the itertools module have been eliminated. (There are still lots of useful functions in the itertools module, just not these.)
Notes @@ -1213,7 +1213,7 @@ except:

os.getcwdu() function

-

Python 2 had a function named os.getcwd(), which returned the current working directory as a (non-Unicode) string. Because modern file systems can handle directory names in any character encoding, Python 2.3 introduced os.getcwdu(). The os.getcwdu() function returned the current working directory as a Unicode string. In Python 3, there is only one string type (Unicode), so os.getcwd() is all you need. +

Python 2 had a function named os.getcwd(), which returned the current working directory as a (non-Unicode) string. Because modern file systems can handle directory names in any character encoding, Python 2.3 introduced os.getcwdu(). The os.getcwdu() function returned the current working directory as a Unicode string. In Python 3, there is only one string type (Unicode), so os.getcwd() is all you need.
Notes @@ -1353,8 +1353,6 @@ do_stuff(a_list) do_stuff(a_list)
-

FIXME: once the rest of the book is written, this appendix should contain copious links back to any chapter or section that touches on these features. -

© 2001–9 Mark Pilgrim