How to launch getattr function in python with additional parameters?

megido picture megido · Jun 12, 2011 · Viewed 24.7k times · Source

I want to call some unknown function with adding parameters using getattr function. Is it possible?

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Jun 12, 2011

Yes, but you don't pass them to getattr(); you call the function as normal once you have a reference to it.

getattr(obj, 'func')('foo', 'bar', 42)