Switching from Python V. 2 to V. 3
Main Reference
A good description of what is different in Python 3 can be found on python.org, at http://docs.python.org/py3k/whatsnew/3.0.html, from which the code snipets below are taken:
Examples Illustrating the Differences
The most obvious difference is that print is now a function and requires parentheses.
Old: print "The answer is", 2*2
New: print("The answer is", 2*2)
Old: print x, # Trailing comma suppresses newline
New: print(x, end=" ") # Appends a space instead of a newline
Old: print # Prints a newline
New: print() # You must call the function!
Old: print >>sys.stderr, "fatal error"
New: print("fatal error", file=sys.stderr)
Old: print (x, y) # prints repr((x, y))
New: print((x, y)) # Not the same as print(x, y)!
Porting old V2 programs to V3
- Theres a 2to3 script that will help (although it may not be able to fully translate old Version 2 code to Version 3): http://diveintopython3.org/porting-code-to-python-3-with-2to3.html