我需要__closure__

Ram*_*hum 7 python python-3.x

我刚刚查看了这个非常有趣的思维导图:

http://www.mindmeister.com/10510492/python-underscore

我想知道一些新的意思,比如__code____closure__.我用Google搜索,但没有具体的东西.有人知道吗?

Jac*_*oyd 7

来自Python 3.0中的新功能

func_X已重命名named的函数属性以使用该__X__表单,从而在函数属性名称空间中释放这些名称以用于用户定义的属性.要机智,func_closure,func_code,func_defaults,func_dict,func_doc,func_globals,func_name已更名为__closure__,__code__,__defaults__,__dict__,__doc__,__globals__,__name__,分别.

基本上,相同的旧Python 2的东西,花哨的新Python 3000名称.

您可以在PEP 232中了解有关大多数这些内容的更多信息


And*_*ikh 6

你实际上在CPython 2.x中有类似的字段:

>>> first = lambda x: lambda y: x
>>> f = first(2)
>>> type(f.func_code)
<type 'code'>
>>> map(type, f.func_closure)
[<type 'cell'>]
Run Code Online (Sandbox Code Playgroud)

编辑:有关这些结构含义的更多详细信息,请阅读Python参考资料的数据模型章节中解释的 "用户定义的函数"和"代码对象" .