How to get method parameter names?

前端 未结 15 2521
眼角桃花
眼角桃花 2020-11-22 09:14

Given the Python function:

def a_method(arg1, arg2):
    pass

How can I extract the number and names of the arguments. I.e., given that I h

15条回答
  •  一向
    一向 (楼主)
    2020-11-22 09:36

    Returns a list of argument names, takes care of partials and regular functions:

    def get_func_args(f):
        if hasattr(f, 'args'):
            return f.args
        else:
            return list(inspect.signature(f).parameters)
    

提交回复
热议问题