views:

51

answers:

1

Possible Duplicate:
Tips on upgrading to python 3.0?

I am beginning Python and Python 3 is hardly a choice today. But I want the new code I write to have no problems running or being converted to Python 3. Are there any issues known that I should keep in mind for this?

+1  A: 

The full correct answer is in the comments, of course - but if you only do one thing to prepare for Python 3, make it learning to use parentheses with 'print'.

Python 2.x:

print 'Hello, World!'

Python 3.x:

print('Hello, World!')

It's the number one most common error in my code when I try to write Python 3.

(And since both methods work with 2.x, you might as well go ahead and get used to using the parens!)

Rini
If you want to use print as a function (with parentheses) rather than as a statement (without parentheses) in Python 2.6 or earlier, you'll need to add this at the beginning of each module/file: `from __future__ import print_function`
blokeley
Actually, I believe it works fine as long as you are printing single values. It is only when printing multiple (comma-separated) values that the meaning of parentheses changes between Python 2 and 3. See http://www.python.org/dev/peps/pep-3105/#backwards-compatibility for full details.
Rini