Ask HN: Why are there 2 Pythons? (2.7 & 3.1.2)

Looks to me like both are stable? Which one should you use for new projects?

  • http://wiki.python.org/moin/Python2orPython3 was created recently to answer just such a question, quite recently in fact (some people were asking similar questions and the issue of the quality of the stock answers was raised in comp.lang.python).

  • If you're doing something completely new that will never interact with older code bases, Python 3 seems like the best choice. This is where the language is ultimately going.

    However, if you have to integrate with almost anything in 2.x land, such as 3rd party libraries, you may have no choice but to keep using 2.x for awhile. As usual, even from this older version, there are ways to voluntarily import future capabilities so that your code is as 3.x-like as possible.

  • Both are stable. Both will continue to be stable for a long time.

    The main difference lies with third party library support. There are a number of third party libraries that don't work with Python 3 yet. They will get ported eventually. If you want to use a library that doesn't support 3, then the choice is made for you.

    The second difference lies with Linux distributions. On most distros you can just install the "python3" package and everything works, on a few distros you'll have to install Python 3 yourself or hunt down the right package repository (my info may be a year behind or so, I'm not sure). This also applies to third party libraries -- even if the library supports Python 3, your distro might not have a package for it, even if it has a package for that library for Python 2.

    It's fairly easy (most of the time) to write code for Python 2.x that converts to Python 3 code with the bundled "2to3" converter. I do this for any script I might ever want to give to someone else or run on a computer that's not mine. Otherwise, I just write straight Python 3 code. Assuming, of course, that I don't need some library.

  • My rule of thumb as to when to use Python 3: once django is ported.

  • If you have to ask, I would highly recommend 2.x ! Nobody of note is using 3.x in production. It's nice, but not backwards compatible with the huge pool of existing code / docs; which is one of python's strongest suits, especially if you're coming to the language fresh.

    The IRC /topic: ;)

    """ Topic for #python: NO LOL | Don't paste in here: use http://paste.pocoo.org/ | http://pound-python.org/ | Include Python version in questions |

    2.x or 3.x? http://tinyurl.com/python2or3 |

    Tutorial: http://docs.python.org/tut/ | FAQ: http://effbot.org/pyfaq/ | New Programmer? http://tinyurl.com/thinkcspy2e | #python-fr #python.de #python-es #python.tw #python.pl #python-br #python-nl #python-ir """

  • why can't you look in the obvious places to answer such a question without asking that on HN? (hint: Python.org and Google)

    (no ill will, but an honest counter-question)

  • Google App Engine SDK uses Python 2.5, I had 2.6 installed and had to revert. 3 drops some features, adds some others. You can import 3.x features in 2.x from __future__, see: http://docs.python.org/library/__future__.html

    One of the less useful features dropped is 'somestring'.encode('rot13') :P

  • Speculatively, there are more than 2 Pythons. Python, like perl has become a family of languages. Some time ago Perl Mongers accepted that Perl 6 was not the next version of Perl but a new language in the Perl family. I suspect Python 3 is to Python 2 as Perl 6 is to Perl 5. Google's Go is also a language in the python family I think.

  • There are many more than 2 pythons. Several versions 2.6, 2.4, 2.2 happily in use in the wild. Not to mention jython, Stackless, IronPython and the like.

    Use the one that fits your new project.

  • It's more like 3, since 2.5 is still pretty popular and doesn't work with 2.7 or 3.1

  • Python 3 is not backwards compatible with Python 2. The developers have always stated that Python 3 will be a 5 year project until the entire standard library is ported.

  • 2.5.4