search

回复内容:

就因为unicode,python3肯定能变成主流 在 3.0 时代我已经开始转向 Python 3 来写自己用的各种脚本了,因为 Python 2.x 的中文编码太纠结了。不过目前 Python 3 的库还是太少,虽然越来越多的库开始支持了。另外,我写过 GAE 程序,用的 Python 2.5,用着非常不顺手。个人认为接下来一两年还是 Python 2.6/2.7 用得最广泛,但终将被 3.x 所取代。我是看好 3.x 的发展的。 谢@胡小樱 邀,受宠若惊。

Python 嘛我两个版本都在用,主要用 Python 2。现在大多数项目都是构建在 Python 2 之上的吧,OS X 自带的 Python 解释器也是 2。

个人感觉 3 和 2 用起来的主要区别就是 encoding 问题终于解决了,默认 Unicode 了。就凭这一点,处理非英语字符串的时候方便好多好多。之前写一个通过 adb 向 Android App 发送消息的脚本的时候,Python 2 的中文字符串 encode/decode 出了好多奇奇怪怪的问题(比如说特定字符转换错误,别的字符都正常),至今无解,让我很无奈。另外一个改变是 print 终于变成函数了,这和其他语言保持了一致。

要从 Python 2 迁移到 3,最大的问题在于很多被广泛应用的库改名、合并、改动,比如说 2 时代被广泛用来做爬虫的 urllib2。网上搜索一下 Python 爬虫,99% 的文章都在介绍 urllib2 的用法;但是 Python 3 里面 urllib2 被合并到 urllib,接口什么的都不一样了,我也没找到任何关于迁移方法的文档。

Python 开发团队对于 2 和 3 的态度也是 3 难以推进的理由之一。两个版本并行开发,这不是明摆着让版本分裂愈演愈烈吗?不如早点学微软把 Python 2 砍掉,长痛不如短痛,开发团队也免去了同时搞两个版本的麻烦。 我看好python4 如果你的工作和文本处理相关得多,那么还是推荐3啊..
2.X的中文处理让你欲仙欲死

初学python的人在选择python版本的时候或许都会存在一些疑惑,到底选python2还是python3呢?或者更精确的说,是python2.7还是3.3呢(这两个版本是目前的主流)?这两个版本有什么不同?最近一段时间我在谷歌和SO上看了很多人的观点,特地来总结一下,或许能解答此时此刻你心中的疑惑。

维基百科在python2.7和3.3这两个版本的不同上给出了非常详细的解答。用这两个版本都各有好处,这取决于你想要得到什么。但是,总体来说“Python 2.x is legacy, Python 3.x is the present and future of the language”

关于最主要的区别,或者说最明显的区别,就是print函数了,在Py2中,我们直接可以print “Hello World!”,但是在Py3中的语法是print (“Hello World!”)。

另外,Py2有更好的库函数的支持,很多库只支持Py2而不支持Py3。所以这是选择Python2的一个非常强大的优势。

但是许多人,包括许多python的开发者都是坚定不移的Py3支持者,archlinux也采用py3为默认版本。为什么呢?因为python3才是符合未来潮流的版本,越来越多的新特性只会支持Py3,这样就显得Py2有点停滞不前。Py3才是未来的主流。

那么说了这么多,作为一个初学者,抑或是一个开发者,怎样选择Python的版本呢?我觉得SO上的一个回答说得非常好:

“Python 3 is a nicer and more consistent language, BUT, there is very limited third-party module support for it. This is likely to be true for at least a couple of years more. So, all major frameworks still run on Python 2, and will continue to do so for a significant time. Therefore, if you learn Python today, you should learn Python 2, because that is the version you are going to end up actually using.”

翻译:“Python3 是一个更棒更持久的语言,但是,支持它的第三方库很有限。这种情况很可能在未来的几年一直持续下去。所以,几乎所有的框架在现在以及未来的一段时间内都会在Py2上运行。因此如果你是一个初学者,那么你应该学Python2,因为那才是你最终要用的。”

虽然这个人给出了选择Py2的答案,但是最终的决定权还是在你手中,毕竟这是一个没有定论的答案。

3.0肯定没人用的,现在的3.x的最新release已经是3.2 了 python.org/download/rel

我个人可能会等到3.3正式release开始尝试使用python 3.x
进入production 至少也要等到常用的库都支持python 3.x之后 不存在看好不看好的问题,3是大势所趋,不过主流的库都还不支持3。等Django,MySQLDB都支持了,用3的时代也就到来了。反正2.7是2.x的最后一个版本。 这和看好不看好有什么关系?

Python3的不向下兼容是Python发展的扬弃的结果。非常决绝有力的决定,给Python注入了更强的生命力。 考古队挖的一手好坟= =

如果是当时提问的时间点的话(2011-03-23),我对 Python 3 持悲观态度,因为那时候的Python 3版本是3.2,最最蛋疼的是unicode的u前缀字符串在Python 3是SyntaxError,我知道这些小事可以在 2to3 中自动修复,但是相当多的人,至少包括我和SQLAlchemy的作者,都非常不喜欢2to3,我是认为 2to3 干涉了我对代码的控制,出了问题还要看是我的问题还是 2to3 自己的问题,单元测试加上 2to3 什么的麻烦死了,而且在最近的 SQLAlchemy 0.9 的 what's new 中相当高调的提到了
Targeting Python 2.6 and Up Now, Python 3 without 2to3
What’s New in SQLAlchemy 0.9?
这一点的顺序甚至高于更有实质意义的 C Extensions Supported on Python 3,当然你也可以理解为重要的是 2.6+这一点

第二蛋疼的是 Python 2.7 几乎有所有的 Python 3.0 ~ 3.2 的新功能的 backport ,这样你让我有什么动力去用Python 3 呢?而且当时 N 多库不相容,尤其是 paramiko ,到现在还不相容,又不像 MySQLdb 有替代-_-||| ,上层的 fabric 也被牵连

不过3.3之后非常不同了,首先最最蛋疼的 u"" 的 SyntaxError 没有了,然后终于有新特性了有木有,generator delegation 功能让我流口水( ̄﹁ ̄),当然纯粹给generator用有点大才小用,果不其然,3.4 (现在还在rc阶段) 的 asyncio 就用的是这种新语法 ( ̄﹁ ̄) 失态了。。。

在 3.3 发布后我才终于有动力修改我的代码,准备 Python 3 的相容性等待迁移,当然。。。虽然unittest都过了还是要观望一下-_-|||
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python vs. C  : Learning Curves and Ease of UsePython vs. C : Learning Curves and Ease of UseApr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

Python vs. C  : Memory Management and ControlPython vs. C : Memory Management and ControlApr 19, 2025 am 12:17 AM

Python and C have significant differences in memory management and control. 1. Python uses automatic memory management, based on reference counting and garbage collection, simplifying the work of programmers. 2.C requires manual management of memory, providing more control but increasing complexity and error risk. Which language to choose should be based on project requirements and team technology stack.

Python for Scientific Computing: A Detailed LookPython for Scientific Computing: A Detailed LookApr 19, 2025 am 12:15 AM

Python's applications in scientific computing include data analysis, machine learning, numerical simulation and visualization. 1.Numpy provides efficient multi-dimensional arrays and mathematical functions. 2. SciPy extends Numpy functionality and provides optimization and linear algebra tools. 3. Pandas is used for data processing and analysis. 4.Matplotlib is used to generate various graphs and visual results.

Python and C  : Finding the Right ToolPython and C : Finding the Right ToolApr 19, 2025 am 12:04 AM

Whether to choose Python or C depends on project requirements: 1) Python is suitable for rapid development, data science, and scripting because of its concise syntax and rich libraries; 2) C is suitable for scenarios that require high performance and underlying control, such as system programming and game development, because of its compilation and manual memory management.

Python for Data Science and Machine LearningPython for Data Science and Machine LearningApr 19, 2025 am 12:02 AM

Python is widely used in data science and machine learning, mainly relying on its simplicity and a powerful library ecosystem. 1) Pandas is used for data processing and analysis, 2) Numpy provides efficient numerical calculations, and 3) Scikit-learn is used for machine learning model construction and optimization, these libraries make Python an ideal tool for data science and machine learning.

Learning Python: Is 2 Hours of Daily Study Sufficient?Learning Python: Is 2 Hours of Daily Study Sufficient?Apr 18, 2025 am 12:22 AM

Is it enough to learn Python for two hours a day? It depends on your goals and learning methods. 1) Develop a clear learning plan, 2) Select appropriate learning resources and methods, 3) Practice and review and consolidate hands-on practice and review and consolidate, and you can gradually master the basic knowledge and advanced functions of Python during this period.

Python for Web Development: Key ApplicationsPython for Web Development: Key ApplicationsApr 18, 2025 am 12:20 AM

Key applications of Python in web development include the use of Django and Flask frameworks, API development, data analysis and visualization, machine learning and AI, and performance optimization. 1. Django and Flask framework: Django is suitable for rapid development of complex applications, and Flask is suitable for small or highly customized projects. 2. API development: Use Flask or DjangoRESTFramework to build RESTfulAPI. 3. Data analysis and visualization: Use Python to process data and display it through the web interface. 4. Machine Learning and AI: Python is used to build intelligent web applications. 5. Performance optimization: optimized through asynchronous programming, caching and code

Python vs. C  : Exploring Performance and EfficiencyPython vs. C : Exploring Performance and EfficiencyApr 18, 2025 am 12:20 AM

Python is better than C in development efficiency, but C is higher in execution performance. 1. Python's concise syntax and rich libraries improve development efficiency. 2.C's compilation-type characteristics and hardware control improve execution performance. When making a choice, you need to weigh the development speed and execution efficiency based on project needs.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)