diff --git a/index.html b/index.html index 02f1b6f..d5d5190 100644 --- a/index.html +++ b/index.html @@ -255,57 +255,61 @@ h3{margin-left:3.5em}

...no one will miss you...

Appendix A. Porting code to Python 3 with 2to3

-

Diving in

-

print statement

-

<> comparison

-

has_key() dictionary method

-

Dictionary methods that return lists

-

Modules that have been renamed or reorganized

-

http package

-

urllib package

-

dbm package

-

xmlrpc package

-

Other modules

-

Relative imports within a package

-

filter() global function

-

map() global function

-

reduce() global function (3.1+)

-

apply() global function

-

intern() global function

-

exec statement

-

execfile statement (3.1+)

-

repr literals (backticks)

-

try...except statement

-

raise statement

-

throw statement

-

long data type

-

xrange() global function

-

raw_input() and input() global functions

-

func_* function attributes

-

xreadlines() I/O method

-

lambda functions with multiple parameters

-

Special method attributes

-

next() iterator method

-

__nonzero__ special class attribute

-

Number literals

-

sys.maxint

-

unicode() global function

-

Unicode string literals

-

callable() global function

-

zip() global function

-

StandardError() exception

-

types module constants

-

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

+
    +
  1. Diving in +
  2. print statement +
  3. Unicode string literals +
  4. unicode() global function +
  5. long data type +
  6. <> comparison +
  7. has_key() dictionary method +
  8. Dictionary methods that return lists +
  9. Modules that have been renamed or reorganized +
      +
    1. http +
    2. urllib +
    3. dbm +
    4. xmlrpc +
    5. Other modules +
    +
  10. Relative imports within a package +
  11. next() iterator method +
  12. filter() global function +
  13. map() global function +
  14. reduce() global function (3.1+) +
  15. apply() global function +
  16. intern() global function +
  17. exec statement +
  18. execfile statement (3.1+) +
  19. repr literals (backticks) +
  20. try...except statement +
  21. raise statement +
  22. throw statement +
  23. xrange() global function +
  24. raw_input() and input() global functions +
  25. func_* function attributes +
  26. xreadlines() I/O method +
  27. lambda functions with multiple parameters +
  28. Special method attributes +
  29. __nonzero__ special class attribute +
  30. Octal literals +
  31. sys.maxint +
  32. callable() global function +
  33. zip() global function +
  34. StandardError() exception +
  35. types module constants +
  36. isinstance() global function (3.1+) +
  37. basestring datatype +
  38. itertools module +
  39. sys.exc_type, sys.exc_value, sys.exc_traceback +
  40. List comprehensions over tuples +
  41. os.getcwdu() function +
  42. Metaclasses +
  43. set() literals (explicit) +
  44. buffer() global function (explicit) +
  45. Whitespace around commas (explicit) +
  46. Common idioms (explicit) +

This site is optimized for Lynx just because fuck you.
I’m told it also looks good in graphical browsers.

© 2001-4, 2009 ark Pilgrim, CC-BY-3.0 diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index 6c3bb1a..ad3f6ad 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -9,7 +9,6 @@ h1:before{counter-increment:h1;content:"Appendix A. "} h2:before{counter-increment:h2;content:"A." counter(h2) ". "} h3:before{counter-increment:h3;content:"A." counter(h2) "." counter(h3) ". "} -td{font-family:monospaced} @@ -674,7 +673,7 @@ except:

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

-

FIXME intro +

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

skip over this table @@ -682,19 +681,23 @@ except: + + + - + - +
NotesPython 3
raise MyExceptionunchanged
raise MyException, "error message" raise MyException("error message")
raise MyException, "error message", a_traceback raise MyException("error message").with_traceback(a_traceback)
raise "error message" unsupported

    -
  1. ... -
  2. ... -
  3. ... +
  4. In the simplest form, raising an exception without a custom error message, the syntax is unchanged. +
  5. The change becomes noticeable when you want to raise an exception with a custom error message. Python 2 separated the exception class and the message with a comma; Python 3 passes the error message as a parameter. +
  6. Python 2 supported a more complex syntax to raise an exception with a custom traceback (stack trace). You can do this in Python 3 as well, but the syntax is quite different. +
  7. In Python 2, you could raise an exception with no exception class, just an error message. In Python 3, this is no longer possible. 2to3 will warn you that it was unable to fix this automatically.

throw statement

FIXME intro @@ -751,7 +754,7 @@ except:

  • The sum() function will also work with an iterator, so 2to3 makes no changes here either. Like dictionary methods that return views instead of lists, this applies to min(), max(), sum(), list(), tuple(), set(), sorted(), any(), and all().

    raw_input() and input() global functions

    -

    FIXME intro +

    Python 2 had two global functions for asking the user for input on the command line. The first, called input(), expected the user to enter a Python expression (and returned the result). The second, called raw_input(), just returned whatever the user typed. This was wildly confusing for beginners and wildly regarded as a “wart” in the language. Python 3 excises this wart by renaming raw_input() to input(), so it works the way everyone naively expects it to work.

    skip over this table @@ -767,15 +770,11 @@ except: - - -
    Notes
    input() eval(input())
    input("prompt")eval(input("prompt"))

      -
    1. ... -
    2. ... -
    3. ... -
    4. ... +
    5. In the simplest form, raw_input() becomes input(). +
    6. In Python 2, the raw_input() function could take a prompt as a parameter. This has been retained in Python 3. +
    7. If you actually need to ask the user for a Python expression to evaluate, use the input() function and pass the result to eval().

    func_* function attributes

    FIXME intro