[Tutor] Grabbing the member functions of an instance?
Daniel Yoo
dyoo@hkn.eecs.berkeley.edu
Tue, 12 Jun 2001 23:18:37 -0700 (PDT)
Out of curiosity, is there a better way of pulling out all the member
functions from an instance? Here's what I have so far:
###
## Python must have something like this already... but I can't recall
## it at the moment. *sigh*
def getBoundMembers(myinstance):
"""Returns all the member functions in a dictionary.
Note: it does not yet look at inherited methods."""
dict = {}
myclass = myinstance.__class__
for member_name in myclass.__dict__.keys():
dict[member_name] = getattr(myinstance, member_name)
return dict
###
I'm planning to use this function with a small toy game I'm making; as
soon as I get it working, I'll be a happy person. *grin*
Thanks for any help!