[Q] __methods__ and __members__ special functions...

Gordon McMillan gmcm at hypernet.com
Tue Jul 20 09:11:52 EDT 1999


Olivier Deckmyn wrote:
> 
> I want to know all the methods available to a instance.
...
> if I make the test with [].__methods__ it works as expected.
> But when I use my own object 
...
> this raises a NameError exception :(
> 
> Why ? Where is __methods__ declared ?
> Why does this work for any instance in the brower.py provided with
> pythonwin ?

__methods__ is an attribute only of types (objects implemented in C); 
essentially it's the table of names -> function pointers that the C 
code uses to tell Python about it's capabilities.  For instance 
objects, methods are function objects living in the object's 
__class__.__dict__ (or perhaps in any __dict__ all along the search 
path from instance to __class__ to __bases__ etc). Mark's browser 
(and dir) will try various things until the object responds.

As you poke deeper, you'll find there's a lot in Python that works 
this way. For example, the code "if x" involves a list of things that 
Python will try on "x" to determine whether x considers itself true 
or false.

- Gordon




More information about the Python-list mailing list