Porting code to Python 3 with 2to3

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

Diving in

FIXME intro

...

print statement

FIXME intro

Notes Python 2 Python 3
print print()
print 1 print(1)
print 1, 2 print(1, 2)
print 1, 2, print(1, 2, end=' ')
print >>sys.stderr, 1, 2, 3 print(1, 2, 3, file=sys.stderr)

...

<> comparison

FIXME intro

Notes Python 2 Python 3
if x <> y: if x != y:
if x <> y <> z: if x != y != z:

...

has_key() dictionary method

FIXME intro

Notes Python 2 Python 3
aDictionary.has_key("PapayaWhip") "PapayaWhip" in aDictionary
aDictionary.has_key(x) or aDictionary.has_key(y) x in aDictionary or y in aDictionary
aDictionary.has_key(x + y) (x + y) in aDictionary
x + aDictionary.has_key(y) x + (y in aDictionary)
aDictionary.has_key(x or y) (x or y) in aDictionary

...

Dictionary methods

FIXME intro

Notes Python 2 Python 3
aDictionary.keys() list(aDictionary.keys())
aDictionary.items() list(aDictionary.items())
aDictionary.iterkeys() iter(aDictionary.keys())
[i for i in aDictionary.iterkeys()] [i for i in aDictionary.keys()]
min(aDictionary.keys()) no change

...

filter() global function

FIXME intro

Notes Python 2 Python 3
filter(aFunction, aList) list(filter(aFunction, aList))
list(filter(aFunction, aList)) no change
filter(None, aList) [i for i in aList if i]
for i in filter(None, aList) no change
[i for i in filter(aFunction, aList)] no change

...

map() global function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

apply() global function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

intern() global function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

exec statement

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

repr literals (backticks)

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

try...except statement

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

raise statement

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

throw statement

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

long data type

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

xrange() global function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

raw_input() global function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

input() global method

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

func_* function attributes

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

xreadlines() I/O method

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

imports

FIXME intro

this includes fixer_imports, fixer_imports2, fixer_urllib

Notes Python 2 Python 3
FIXME FIXME

lambda functions with multiple parameters

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

__class__ special class attribute

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

next() iterator method

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

__nonzero__ special class attribute

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

Number literals

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

sys.maxint

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

unicode() global function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

Unicode string literals

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

callable() global function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

zip() global function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

StandardError() exception

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

types module constants

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

basestring datatype

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

itertools module

FIXME intro

this includes fixer_itertools, fixer_itertools_imports

Notes Python 2 Python 3
FIXME FIXME

Relative imports

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

sys.exc_type, sys.exc_value, sys.exc_traceback

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

List comprehensions over tuples

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

os.getcwdu() function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

Metaclasses

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

set() literals

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

buffer() global function

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

Whitespace around commas

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...

Common idioms

FIXME intro

Notes Python 2 Python 3
FIXME FIXME

...