dynamic call of a function
Paul Rubin
phr-n2001d at nightsong.com
Fri Oct 19 05:29:38 EDT 2001
More information about the Python-list mailing list
Fri Oct 19 05:29:38 EDT 2001
- Previous message (by thread): dynamic call of a function
- Next message (by thread): dynamic call of a function
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
anthony harel <anthony.harel at c-s.fr> writes: > I have got a string that contains the name of the function I > want to call but I don't want to do something like this : > > if ch == "foo" : > self.foo( ) > elif ch == "bar" > self.bar( ) > .... > > Is it possible to do sommething like that : > ch = "foo" > apply(ch, ( ))??? Try this: ch = "foo" func = getattr(self, ch) func () Of course you could also just say getattr(self,"foo")().
- Previous message (by thread): dynamic call of a function
- Next message (by thread): dynamic call of a function
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list