Calling a method using an argument

Diez B. Roggisch deetsNOSPAM at web.de
Thu Feb 3 11:02:25 EST 2005


Diez B. Roggisch wrote:

> def test(self,arg):
>     return getattr(self, arg)
> 

Oops, missed the calling:

def test(self,arg):
    return getattr(self, arg)()


If you have more args, do this:

def test(self, *args):
    return getattr(self, args[0])(*args[1:])


-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list