Search code examples
pythongetattr

How to launch getattr function in python with additional parameters?


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


Solution

  • 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)