开发者

Why should I use python 3.1 instead of python 2.6?

After reading some benchmarks, I noticed that python 开发者_高级运维3.1 is slower than python 2.6, especially with I/Os.

So I wonder what could be the good reasons to switch to Python 3.x ?


Go to 3.1. Unless your code is run-once (which at almost never is). 2.6 has no future, and version 3 is the future, unless you are into time travel.

They are working on 3.1 and I can assure you the speeds will soon be up to par, and then exceed 2.6 speeds.


Largely because of the new I/O library. This, however, has been completely rewritten to C in Python 3.2 and 2.7. I think the performance numbers are pretty close right now if you compare it to 3.2.

edit: I confused the version numbers. Nevermind.


Python 3 does introduce some new language features too. One of my favorite is the new nonlocal keyword, which finally lets you write certain closures nicely, such as:

def getter_setter():
    x = 0
    def getter():
        return x
    def setter(val):
        nonlocal x
        x = val
    return (getter, setter)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜