import inspect
class Foo(object):
pass
if __name__ == '__main__':
print type(Foo.__init__)
print inspect.getsourcelines(Foo.__init__)
Output:
<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
Googling gives very little useful information about what, exactly, a wrapper_descriptor is, and why an empty class has an __init__
method that is not a method, but rather a wrapper_descriptor.
What exactly is going on here? Do all classes without __init__
methods have one of these wrapper_descriptor things? Why is there an __init__
in the class dict at all?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…