Finding the public callables of self

Lonnie Princehouse finite.automaton at gmail.com
Thu Feb 9 11:43:41 EST 2006


import inspect
myCallables = [name for name, value in inspect.getmembers(self) if not
name.startswith('_') and callable(value)]


Instance methods aren't in self.__dict__ because they're a part of the
class.  To made a comprehensive list of all the attributes available to
an instance, you have to traverse the attribute dictionaries of the
instance, its class, and all of the base classes in the right order.
(inspect.getmro returns the base classes in method resolution order)




More information about the Python-list mailing list