convert a string to a method call ?

Oleg Broytmann phd at phd.pp.ru
Thu Nov 15 11:38:47 EST 2001


On Thu, Nov 15, 2001 at 08:29:39AM -0800, Bruce Edge wrote:
> I have an object, say xObj, which has a bunch of methods.
> I have the method I want to call in a string, say str.
> 
> How do I call method str on xObj?
> Use eval? If so, the syntax eludes me.

   method = getattr(xObj, "str")
   method(param1, param2...)

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list