<method-wrapper>.__self__

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Wed Jul 21 06:24:34 EDT 2004


What's the difference between a built-in method and a method-wrapper
object?  Why has only the former a __self__, even though both are
tied to the object on which to perform the operation?
Why do list.pop and list.__len__ have different types at all?

>>> [5].pop.__self__
[5]
>>> [5].__len__.__self__
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'method-wrapper' object has no attribute '__self__'

>>> [5].pop
<built-in method pop of list object at 0x1c3770>
>>> [5].__len__
<method-wrapper object at 0x1bf210>

>>> list.pop
<method 'pop' of 'list' objects>
>>> list.__len__
<slot wrapper '__len__' of 'list' objects>

-- 
Hallvard



More information about the Python-list mailing list