What Python version can you please recommend for a long-term (years) project? Should one use 2.6+ or 3.x is already stable? (only standard libraries are required)
UPDATE开发者_如何学C: according to the answers below, Python 3.x still has critical bugs. Please also see Python's list of bugs.
This is why you should use Python 3.x:
Python 2.x:
>>>True = False
>>>True
False
Python 3.x:
>>> True = False
File "<stdin>", line 1
SyntaxError: assignment to keyword
Source: Strangest language feature
Prejudice: But so many packages are not Python 3 ready yet
This is (a) not true (source) and (b) not important to a beginner.
I think it boils down to how closely you can control the environment in which your application will run. If you are producing a piece of software in which your customer will 'install' python to run your software, then you might as well use the latest release (Python 3.x). If you are targeting existing python installs then choosing 2.5 or 2.6 compatibility would be best since those are more widespread.
Python 3.x is stable. That is not the issue. The issue with it is compatibility. If you have the ability to use the latest and greatest then you should use the new version. For new projects, 3.x would be the obvious choice.
There's nothing wrong with Python 3, but many libraries haven't been ported yet. For example, from PyGame FAQ:
Python 3 support is incomplete and still in the development stage
And from NumPy:
Support for Python 3 is planned, but not yet scheduled.
It all depends on how important 3rd party libraries are to you, and whether they're ported yet.
The good thing about Python3 is that there is a automatic way to port your programs from Python2. But the program has to meet certain criteria.
I think the best approach for now is to write Python2 code and test it in Python3 test mode (run python -3 program.py
). This way you don't have to worry about missing libraries now and you can convert your program to Python3 as soon as that makes sense.
THC4k mentions 2to3, and I just wanted to point out that there's also a 3to2 package. I've never used either package, but I've heard that 3to2 is more forgiving than 2to3.
Edit: just wanted to emphasize what others have suggested: If you choose to use one of these converters to release your software for either 2.6 or 3.0, you'll probably want to have a solid testing system in place (unittest, doctest, etc) with decent test coverage to sleep soundly at night!
If you are starting your project now, and all the third party libraries you want to use are already ported to Python 3, and your target operating system (I really mean linux distribution) packages Python 3, then sure.
Go ahead, use Python 3.
精彩评论