Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Help me understand Python 2.x vs 3.x
6 points by sabj on Dec 17, 2010 | hide | past | favorite | 4 comments
I've been trying to teach myself Python recently, with mixed success. (Recently, I have been a little seduced by the availability of resources and community around Ruby, since my interest is mostly in doing things on the web - so e.g. Rails vs. Django, even though I conceptually like the later, for some logistical reasons I am finding the former to be a little tempting to experiment with more.)

However, a principal question I still have concerns the different versions of Python. [http://wiki.python.org/moin/Python2orPython3]

I have read the Wiki and understand some of the differences, or lack-of-differences, but am still unclear. For example, I know some servers or services (eg Google App Engine) are at one version, while others are at another. Should I be concerned about any of this? Is there any reason to try to use Python 3 at present? Etc?

Thanks for any insights here!



If you're a daredevil you can write your code in Python 3 directly. As you said, some service providers don't offer it yet, and some third party libraries aren't compatible with it.

What most developers do to support both Python 2 and 3 is to write the code in as-portable-as-possible Python 2 and convert it using the '2to3' tool (or similar, more intelligent tools, do a search) before each deployment/release.

Portable means "use no modules that are deprecated in 3.0", using modules that simply have another name is OK. Language constructs are (usually) simply converted. In that case you have to test in both Python 2 and 3.


I think this [https://docs.google.com/viewer?url=http://www.python.org/doc...] slideshow presentation by Guido can shed some light on the syntactical and other differences between python2 and python3.


Django won't work with Python 3 for a few years yet, so if you want to use Django, stick with 2.


There was this, too...

I was saying to myself, OK, time to learn Python so I can try to make something cool with Django. What Python to learn? Oh, wait...

I wasn't sure why I would write the code in Python 2 and then convert it to Python 3, if it could just be run in Python 2 anyways.

In any event, thanks for some of the clarification, HN-folks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: