Calling a function dynamically
antonmuhin at rambler.ru
Thu Jan 8 16:53:57 CET 2004
> I would like to call a function whose name I supply at runtime.
> Something like this but it didn't work
> functionName = 'run'
> instance = ClassDef()
> args = [1, 2]
> #want the dynamic equivalant of
> #This didn't work cause there was no __call__ attribute. Why?
> value = instance.__call__[functionName](*args)
> Thanks Joey
This should work:
More information about the Python-list