What’s New in Python 2.7

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 上的对于某一问题改动的讨论。只要可能,本文链接了对于每个改动的漏洞/补丁。

The Future for Python 2.x

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.

  • 对比与早期的2.X版本,2.7发布版本非常可能会拥有更长的维护时间。在过渡到3.X的同时,Python 2.7将会继续维护,并且开发者计划支持2.7的漏洞修复达两年以上。
  • 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').

  • 因为开发者的意愿,做出了关闭警告的决定。DeprecationWarning和它的后代现在是被忽略的,除非有其他的请求,否则将会阻止用户看到由应用触发的警告。

Python 3.1 Features

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:

  • The syntax for set literals ({1,2,3} is a mutable set).
  • Dictionary and set comprehensions ({i: i*2 for i in range(3)}).
  • Multiple context managers in a single with statement.
  • A new version of the io library, rewritten in C for performance.
  • The ordered-dictionary type described in PEP 372: Adding an Ordered Dictionary to collections.
  • The new "," format specifier described in PEP 378: Format Specifier for Thousands Separator.
  • The memoryview object.
  • A small subset of the importlib module, described below.
  • The repr() of a float x is shorter in many cases: it’s now based on the shortest decimal string that’s guaranteed to round back to x. As in previous versions of Python, it’s guaranteed that float(repr(x)) recovers x.
  • Float-to-string and string-to-float conversions are correctly rounded. The round() function is also now correctly rounded.
  • The PyCapsule type, used to provide a C API for extension modules.
  • The PyLong_AsLongAndOverflow() C API function.

Other new Python3-mode warnings include:

  • operator.isCallable() and operator.sequenceIncludes(), which are not supported in 3.x, now trigger warnings.
  • The -3 switch now automatically enables the -Qwarn switch that causes warnings about using classic division with integers and long integers.

Python 2.7的新特性相关推荐

  1. 火了!16岁高中生做的 Python 3.9 八大新特性图

    金磊 发自 凹非寺 量子位 报道 | 公众号 QbitAI Python3.9,「千呼万唤始出来」. 先来速看下此次发布版本的重点. 新语法特性: PEP 584,为 dict 增加合并运算符. PE ...

  2. Python持续更新的新特性

    一. python 3.6 更新的新特性 1.1 f-Strings:格式化输出 好消息是,F字符串在这里可以节省很多的时间.他们确实使格式化更容易.他们自Python 3.6开始加入标准库.您可以在 ...

  3. Python 3.6部分新特性

    Python 3.6.0于2016年12月23日正式发布,除了本文提到的这一部分比较重要的新特性之外,还有很多标准库也新增了部分功能,等有时间再慢慢整理. 1.内置字典对象dict进行了重新设计,可以 ...

  4. python 3.10 的新特性用不到,你来打我!!!

    文 | 某某白米饭 来源:Python 技术「ID: pythonall」 python 3.10 已经在 10月 4 号发布了,这次更新了错误语法提示对 python 新手更加友好.好几个新的特性非 ...

  5. Python培训分享:Python新版本中的6个新特性

    Python在几年做了一个全面的升级,此次Python升级中有6个新特性,本期小编为大家介绍的Python培训教程就是关于介绍Python新版本中的6个新特性的,来看看下面的详细介绍. Python培 ...

  6. Python 3.9来了!这十个新特性值得关注

    选自towardsdatascience 作者:Farhad Malik 机器之心编译 编辑:陈萍 近日,Python 3.9 发布,并开发了一些新特性,包括字典合并与更新.新的解析器.新的字符串函数 ...

  7. 您应该知道Python 3.10中的新特性!

    Hello,大家好,我是Alex,欢迎来到每周博客! 这篇博客来给大家介绍一下Python 3.10的新特性. Python 3.10版本带来了一些很棒的新功能和改进. 结构模式匹配 结构模式匹配可以 ...

  8. python 3.9特性_Python 3.9来了!这十个新特性值得关注

    选自towardsdatascience 作者:Farhad Malik 机器之心编译 编辑:陈萍 近日,Python 3.9 发布,并开发了一些新特性,包括字典合并与更新.新的解析器.新的字符串函数 ...

  9. Python 3.10 中的 6 个新特性,你体验了吗?

    作者 | Sara A. Metwalli 译者 | 有数可据 出品 | CSDN(ID:CSDNnews) 新的 Python 版本推出了有趣的新功能. Python 是当今最流行的编程语言之一.它 ...

  10. python3.8的用法_体验一下 Python 3.8 带来的主要新特性

    学习理解一个软件非常好的方法就是跟随每一个版本演进的新特性,好比一个人被别人看着长大的,知子莫若父.因此每个版本的 Changelogs 或 What's New 是非常值得一读的,见 What's ...

最新文章

  1. 4、Mysql 主从复制报错[ERROR] [MY-013117] 踩坑
  2. 游戏外挂技术:编程实现内存检索(检索内存中指定数据)
  3. 一维数组去重处理法一(C语言)
  4. wordpress插件-WP Rocket 3.9.3缓存加速插件免授权版
  5. maven打的包带exec包比不带的大_spring boot maven打包可执行jar包缺少依赖包的问题...
  6. 2020法研杯比赛阅读理解任务冠军参赛总结
  7. 如何将mov转换成mp4?详细的步骤分享
  8. 数据结构:八种数据结构大全
  9. 站内信“数据库设计思路”
  10. 路由之HSRP热备份
  11. Shader小技巧-翻转uv
  12. python模块之Queue
  13. Python Scrapy使用实例讲解
  14. 当机器有了“视力”,它会抢人类的饭碗并取代人类吗?
  15. [Tyvj1474]打鼹鼠
  16. 资管软件源码|信管家软件源码|通达信陪资|博易大师软件
  17. SpringBootMybatisPlus 种子项目
  18. android 异形按钮,异形按钮的实现方法(例如:斜角按钮,星形按钮)
  19. 173-C++面向对象高级开发-上(侯捷)
  20. abap CA CO CS 模式匹配的使用方法

热门文章

  1. ElasticSearch笔记整理(三):Java API使用与ES中文分词
  2. Python版:实现双十一秒杀,防止超限
  3. 依旧是输入输出(存字符矩阵,空格,换行)
  4. PHP网站安全日志系统开发与部署
  5. String类型的方法总结
  6. Codeforces Round #387 (Div. 2) 747E
  7. Elite Model的NetSuite ERP国内成功实例!
  8. [渣译文] SignalR 2.0 系列: SignalR简介
  9. 最佳软件开发实践指导
  10. 搭建Web和FTP站点