[Q] __methods__ and __members__ special functions...

Olivier Deckmyn olivier.deckmyn at mail.dotcom.fr
Tue Jul 20 07:38:20 EDT 1999


Hi all !

I want to know all the methods available to a instance.

Here is a copy of the official FAQ :
"""
4.60. Why doesn't dir() work on builtin types like files and lists?
It should have -- and it does starting with Python 1.5 (currently in
development -- see Questions 1.13 and 2.10).
Using 1.4, you can find out which methods a given object supports by looking
at its __methods__ attribute:


    >>> List = []
    >>> List.__methods__
    ['append', 'count', 'index', 'insert', 'remove', 'reverse', 'sort']
""""

if I make the test with [].__methods__ it works as expected.
But when I use my own object :

class ClassA:
    def __init__(self):
        pass

    def myMethod(self, a)
        return a*2

if I try __methods__ on a fresh instance :

a=ClassA()
a.__methods__

this raises a NameError exception :(

Why ? Where is __methods__ declared ?
Why does this work for any instance in the brower.py provided with pythonwin
?

Please help !

Olivier.









More information about the Python-list mailing list