"Sagari" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Thanks to everyone for all the comments. I am migrating from PHP to | Python and I am looking for the means to port a controller code that | would, roughly speaking, call a certain method of a certain class | (both class and method names taken from user input). Putting aside | input verification (by the moment I perform the call input must have | been verified), what would be the recommended way of doing the trick?
Use getattr(ob, name). Suppose mod = <module with classes, imported as 'mod'> cname = <class name from user> mname = <method name from user> Then classobj = getattr(mod, cname) methobj = getattr(classobj, mname) However: Python generally uses methods for instance methods. Would you be creating an instance of the class (easily done -- inst = classobj(args)) before calling the method? If so, call methodobj(inst, args). If not, I wonder I you should really be using (Python) classes. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list