Reflection: Calling Methods Dynamically by Name
harrc at my-deja.com
harrc at my-deja.com
Thu Jan 11 00:22:40 EST 2001
Question for Guido or language experts:
Does Python have the ability to call methods of a class by name? For
example, I have a string: "ProcessData" and the class MyClass has a
method called ProcessData. Is there a way I can do something like this:
mc = MyClass()
str = "ProcessData"
args = ("Data", 1, 3)
CallMethodByName(mc, str, args)
or perhaps:
mc = MyClass()
str = "ProcessData"
args = ("Data", 1, 3)
mc.CallMethodByName(str, args)
This reflection-esque behavior would be very useful. Any ideas?
Thanks,
Chad Harrington
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list