Getting a list of an object's methods?

Jeremy Yallop jeremy at jdyallop.freeserve.co.uk
Mon Jun 23 17:05:20 EDT 2003


Gerrit Holl wrote:
> Jeremy Yallop wrote:
>> Unfortunately, this isn't any better than the original idea of using
>> dir(), since inspect.getmembers is implemented using dir().  As the OP
>> noted, dir() isn't reliable.  For example, 'mro' isn't in int's dir(),
>> although it is (the name of) a method of type and in type's __dict__.
> 
> Hm, how does readline does this? I use readline and I do get 'mro'
> for an int when pressing tab:
[snip] 
> Readline appears to be implemented in C. Hmm...

Readline is indeed implemented in C, but the function which completes
the partial member names is written in Python: see the Completer class
in the rlcompleter module.  The actual implementation is rather
simple: it calls dir on the instance, its class and (recursively) its
class's bases.

The code is fairly straightforward and might at least give the OP some
ideas.

Jeremy.




More information about the Python-list mailing list