【发布时间】:2013-03-19 23:03:59
【问题描述】:
import inspect
class Foo(object):
pass
if __name__ == '__main__':
print type(Foo.__init__)
print inspect.getsourcelines(Foo.__init__)
输出:
<type 'wrapper_descriptor'>
Traceback (most recent call last):
*snip*
File "/usr/lib/python2.7/inspect.py", line 420, in getfile
'function, traceback, frame, or code object'.format(object))
TypeError: <slot wrapper '__init__' of 'object' objects> is not a module, class, method, function, traceback, frame, or code object
Google 几乎没有提供关于 wrapper_descriptor 究竟是什么以及为什么空类有一个__init__ 方法而不是方法而是 wrapper_descriptor 的有用信息。
这里到底发生了什么?没有__init__ 方法的所有类都具有这些 wrapper_descriptor 事物之一吗?为什么类字典中有__init__?
【问题讨论】:
标签: python initialization