Author: | A.M. Kuchling (amk at amk.ca) |
---|---|
Release: | 2.7.2 |
Date: | August 25, 2011 |
This article explains the new features in Python 2.7. Python 2.7 was released on July 3, 2010.
本文解释了Python2.7中的新特性。该版本于2010年7月3日发布。
Numeric handling has been improved in many ways, for both floating-point numbers and for the Decimal class. There are some useful additions to the standard library, such as a greatly enhanced unittest module, the argparse module for parsing command-line options, convenient OrderedDict and Counter classes in the collections module, and many other improvements.
数值处理能力在许多方面有所提高, 包括浮点数和小数处理。一些实用的模块加入到了标准库中,例如:
-- 大幅加强了的 unittest 模块;
-- 用于解析命令行参数的 argparse 模块;
-- collections 模块中便利的 OrderedDict 和 Counter 类;
-- 以及许多其他的改进
Python 2.7 is planned to be the last of the 2.x releases, so we worked on making it a good release for the long term. To help with porting to Python 3, several new features from the Python 3.x series have been included in 2.7.
计划中 Python 2.7 会是 2.x 家族的最后一员, 所以长期以来我们致力于将其打造成为良好的发布版本。 为了方便大家逐渐适应 Python 3, 一些 Python 3.x 系列的特性被引入了 Python 2.7。
This article doesn’t attempt to provide a complete specification of the new features, but instead provides a convenient overview. For full details, you should refer to the documentation for Python 2.7 at http://docs.python.org. If you want to understand the rationale for the design and implementation, refer to the PEP for a particular new feature or the issue on http://bugs.python.org in which a change was discussed. Whenever possible, “What’s New in Python” links to the bug/patch item for each change.
本文不打算提供关于新特性的完整描述,而是提供了一个方便的概述。对于完全的细节,你应该去参考http://bugs.python.org 上的Python2.7文档。如果你想要理解设计和实现的基本原理,参考关于某一特性新属性的PEP或在http://bugs.python.org 上的对于某一问题改动的讨论。只要可能,本文链接了对于每个改动的漏洞/补丁。
Python 2.7 is intended to be the last major release in the 2.x series. The Python maintainers are planning to focus their future efforts on the Python 3.x series.
This means that 2.7 will remain in place for a long time, running production systems that have not been ported to Python 3.x. Two consequences of the long-term significance of 2.7 are:
It’s very likely the 2.7 release will have a longer period of maintenance compared to earlier 2.x versions. Python 2.7 will continue to be maintained while the transition to 3.x continues, and the developers are planning to support Python 2.7 with bug-fix releases beyond the typical two years.
A policy decision was made to silence warnings only of interest to developers. DeprecationWarning and its descendants are now ignored unless otherwise requested, preventing users from seeing warnings triggered by an application. This change was also made in the branch that will become Python 3.2. (Discussed on stdlib-sig and carried out in issue 7319.)
In previous releases, DeprecationWarning messages were enabled by default, providing Python developers with a clear indication of where their code may break in a future major version of Python.
However, there are increasingly many users of Python-based applications who are not directly involved in the development of those applications. DeprecationWarning messages are irrelevant to such users, making them worry about an application that’s actually working correctly and burdening application developers with responding to these concerns.
You can re-enable display of DeprecationWarning messages by running Python with the -Wdefault (short form: -Wd) switch, or by setting the PYTHONWARNINGS environment variable to "default" (or "d") before running Python. Python code can also re-enable them by calling warnings.simplefilter('default').
Much as Python 2.6 incorporated features from Python 3.0, version 2.7 incorporates some of the new features in Python 3.1. The 2.x series continues to provide tools for migrating to the 3.x series.
A partial list of 3.1 features that were backported to 2.7:
Other new Python3-mode warnings include: