Ask for a method of using python, about the function property getattr based on an instance.

Hello everyone, I have a requirement now. Now, for example, I have a class. There are no specified functions in the class. The effect I need to do is
object.fun ( kwargs) or objcet.func_path.func ( kwargs)

.

object is my instantiated object, and then I give him a parameter inside fun and fun, how do I get fun and his parameters in my object, and the other is how to get func_path and func and his parameters. Thank you.

Jun.01,2022

>>> class Obj:
...     def __init__(self):
...             pass
...     def func(self, a, *args, **kwargs):
...             pass
... 
>>> getattr(Obj, 'func')
<function Obj.func at 0x7f1e2302b048>
>>> f = getattr(Obj, 'func')
>>> f.__code__.co_varnames
('self', 'a', 'args', 'kwargs')
Menu