How do i call a method by a string name using python?
        Posted  
        
            by gath
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by gath
        
        
        
        Published on 2010-05-28T15:14:03Z
        Indexed on 
            2010/05/28
            15:22 UTC
        
        
        Read the original article
        Hit count: 285
        
I have the following class;
class myStringMethod():
    def __init__(self):
        self.func_list= [('func1','print_func1()'),('func2','print_func2()')]
    def print_func1(self, name):
        print name
    def print_func2(self, name):
        print name
    def call_func_by_name(self):
        for func in self.func_list:
            getattr(self, func[1])('Func Name')
if __name__=='__main__':
    strM = myStringMethod()
    strM.call_func_by_name() #Nothing prints out!
No functions get called out, what am i missing?
gath
© Stack Overflow or respective owner