How to dynamically call a method in python?
问题 I would like to call an object method dynamically. The variable "MethodWanted" contains the method I want to execute, the variable "ObjectToApply" contains the object. My code so far is: MethodWanted=".children()" print eval(str(ObjectToApply)+MethodWanted) But I get the following error: exception executing script File "<string>", line 1 <pos 164243664 childIndex: 6 lvl: 5>.children() ^ SyntaxError: invalid syntax I also tried without str() wrapping the object, but then I get a "cant use +