Size: 4448
Comment:
|
← Revision 14 as of 2009-12-25 07:16:15 ⇥
Size: 4826
Comment: converted to 1.6 markup
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
'''即将到来的 Python 3000 '''::-- ["swordsp"] [[[DateTime]]] [[TableOfContents]] | '''即将到来的 Python 3000 '''::-- [[swordsp]] [<<DateTime>>] <<TableOfContents>> |
Line 5: | Line 5: |
* [wiki:peps:pep-3000/ PEP 3000] -- Python 3000 * [wiki:peps:pep-3099/ PEP 3099] -- Things that will Not Change in Python 3000 * [wiki:peps:pep-3100/ PEP 3100] -- Miscellaneous Python 3.0 Plans |
* [[peps:pep-3000/|PEP 3000]] -- Python 3000 * [[peps:pep-3099/|PEP 3099]] -- Things that will Not Change in Python 3000 * [[peps:pep-3100/|PEP 3100]] -- Miscellaneous Python 3.0 Plans |
Line 10: | Line 10: |
[wiki:peps:pep-3104/ PEP 3104] | [[peps:pep-3104/|PEP 3104]] |
Line 12: | Line 12: |
这算是个老问题了: {{{ #!python |
这算是个老问题了,在 python 中一直以来在嵌套函数中无法重新绑定外部名字空间的名字,只能重新绑定 global 或者 local 名字空间,比如: {{{#!python |
Line 20: | Line 18: |
#目前的python版本中,这里无法修改 test1 中的那个 a。 | #目前的python版本中,这里无法重新绑定 test1 中的那个 a。 |
Line 22: | Line 20: |
而 python3000 中有望通过使用 nonlocal 关键字访问外层名字空间: | 而 python3000 中有望通过使用 nonlocal 关键字来重新绑定外层名字空间: |
Line 31: | Line 29: |
# 这样就把 test1 中的 a 修改了。 | # 这样就可以重新绑定 test1 名字空间中的名字 a 了。 |
Line 33: | Line 31: |
nonlocal 会从最靠近的名字空间不断向外搜索。 | nonlocal 会从最靠近的名字空间开始向外搜索。 |
Line 36: | Line 34: |
[wiki:peps:pep-3107/ PEP 3107] | [[peps:pep-3107/|PEP 3107]] |
Line 46: | Line 44: |
[wiki:peps:pep-3108/ PEP 3108] | [[peps:pep-3108/|PEP 3108]] |
Line 50: | Line 48: |
[wiki:peps:pep-3115/ PEP 3115] | [[peps:pep-3115/|PEP 3115]] |
Line 78: | Line 76: |
[wiki:peps:pep-3102/ PEP 3102] | [[peps:pep-3102/|PEP 3102]] |
Line 105: | Line 103: |
==== Bytes literals in Python 3000 ==== [[peps:pep-3112/|PEP 3112]] Python3000 把以前的 unicode 对象变成了字符串,而以前的字符串就变成了字节数组。 {{{#!python b'hello world!'}}} |
|
Line 106: | Line 111: |
* 来自 [http://www.artima.com/weblogs/index.jsp?blogger=guido Guido van Rossum 个人 blog] 的关于 Python 3000 开发进度和展望的最新消息 * [http://www.artima.com/weblogs/viewpost.jsp?thread=98196 The fate of reduce() in Python 3000] * [http://www.artima.com/weblogs/viewpost.jsp?thread=155123 Python 3000 - Adaptation or Generic Functions?] * [http://www.artima.com/weblogs/viewpost.jsp?thread=157004 Python 3000 Slides] . Guido 于2006年4月在某次会议上的讲稿。[http://www.python.org/doc/essays/ppt/accu2006/Py3kACCU.ppt 下载] * [http://www.artima.com/weblogs/viewpost.jsp?thread=173453 Python Sprint Report] |
* 来自 [[http://www.artima.com/weblogs/index.jsp?blogger=guido|Guido van Rossum 个人 blog]] 的关于 Python 3000 开发进度和展望的最新消息 * [[http://www.artima.com/weblogs/viewpost.jsp?thread=98196|The fate of reduce() in Python 3000]] * [[http://www.artima.com/weblogs/viewpost.jsp?thread=155123|Python 3000 - Adaptation or Generic Functions?]] * [[http://www.artima.com/weblogs/viewpost.jsp?thread=157004|Python 3000 Slides]] . Guido 于2006年4月在某次会议上的讲稿。[[http://www.python.org/doc/essays/ppt/accu2006/Py3kACCU.ppt|下载]] * [[http://www.artima.com/weblogs/viewpost.jsp?thread=173453|Python Sprint Report]] |
Line 114: | Line 119: |
[[PageComment2]] |
即将到来的 Python 3000 ::-- swordsp [2025-09-26 22:51:38]
Contents
概述
PEP 3000 -- Python 3000
PEP 3099 -- Things that will Not Change in Python 3000
PEP 3100 -- Miscellaneous Python 3.0 Plans
PEPs
Access to Names in Outer Scopes
- 这算是个老问题了,在 python 中一直以来在嵌套函数中无法重新绑定外部名字空间的名字,只能重新绑定 global 或者 local 名字空间,比如:
- 而 python3000 中有望通过使用 nonlocal 关键字来重新绑定外层名字空间: nonlocal 会从最靠近的名字空间开始向外搜索。
Function Annotations
- 可以可选地给函数添加元数据,利用这些元数据可以干很多事情,比如文档生成、类型检查、方便与静态语言之间的交互等等,看个例子:
Standard Library Reorganization
- 重新组织标准库,主要是移除和重命名。
Metaclasses in Python 3000
Python 3000 在 metaclass 方面的大改动! 新的 class 定义语法和函数调用几乎一样,除了 def 换成了 class:
另外以前的 metaclass 第一次被调用时,class 的属性字典就已经构建出来了,metaclass 无法控制这个过程,使得有些功能无法实现,比如保持属性定义的顺序! Python 3000 中的 metaclass 可以定义一个叫 __prepare__ 的 class method,返回一个 dict like 对象(只需要定义 __setitem__ 方法),用来控制 class 属性的存储。这个过程用伪码表示大致如下:
可以看出,class 定义时传入的参数实际上都是传给 metaclass 的。
Keyword-Only Arguments
我们知道 python 向来就有灵活的参数传递机制,通过 × 和 ×× 可以实现非常灵活的参数传递。但仍然有一些问题还没有很好的解决,在以前你总是可以把位置实参传给关键字形参,或是把关键字实参传给位置形参,比如:
这些都是合法的,但是现在你不希望位置参数和关键字参数混在一起,你想要实现这样的函数声明:
这在以前是语法错误,但现在成为可能! 又或者你现在不想让用户传递任意数量的位置参数,只允许两个位置参数,你可以这样定义:
并且这些改变完全不会破坏现有的代码,所以有望在 2.x 的版本里就看得到
Bytes literals in Python 3000
Python3000 把以前的 unicode 对象变成了字符串,而以前的字符串就变成了字节数组。
1 b'hello world!'
进展
来自 Guido van Rossum 个人 blog 的关于 Python 3000 开发进度和展望的最新消息