Reflection: Calling Methods Dynamically by Name

D-Man dsh8290 at rit.edu
Thu Jan 11 07:51:01 EST 2001


On Thu, Jan 11, 2001 at 01:41:34PM +0700, Prateep Siamwalla wrote:
| Chad,
| 
| You will want to use getattr() and apply()
| 

Is it better to use getattr() and apply() than to use exec?

For example,

mc = MyClass()
funcname = "ProcessData"
args = ("Data", 1, 3)
exec( "mc." + funcname + "('Data' , 1 , 3 ) " )

-D





More information about the Python-list mailing list