How to launch getattr function in python with additional parameters?

前端 未结 3 1825
栀梦
栀梦 2021-01-31 09:08

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

3条回答
  •  醉话见心
    2021-01-31 09:22

    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)
    

提交回复
热议问题