Fredrik Lundh fredrik at pythonware.com
Mon Dec 8 20:03:41 CET 2003

Jacek Generowicz wrote:

> Where can I find information on the __self__ attribute of builtin
> functions ?

it's the same thing as im_self, but for methods/functions
implemented in C.

that is, if "x" is a bound method, "x.__self__" is the object
that method is bound to:

>>> x = ["spam"]
>>> x.count
<built-in method count of list object at 0x0083D130>
>>> dir(x.count)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__self__', '__setattr__', '__str__']
>>> x.count.__self__

for unbound methods (and functions), it's set to None.


More information about the Python-list mailing list