python get number of arguments of a function 1

python get number of arguments of a function

from inspect import signature

def someMethod(self, arg1, kwarg1=None):
    pass

sig = signature(someMethod)
print(len(params))  # 3

Here is what the above code is Doing:
1. The function someMethod is defined.
2. The signature of someMethod is obtained using the signature function.
3. The number of parameters of someMethod is printed.

Similar Posts