Get a list/tuple/dict of the arguments passed to a function?

前端 未结 8 1145
梦如初夏
梦如初夏 2020-12-01 13:17

Given the following function:

def foo(a, b, c):
    pass

How would one obtain a list/tuple/dict/etc of the arguments passed in, wit

相关标签:
8条回答
  • 2020-12-01 14:11

    You've specified the parameters in the header?

    Why don't you simply use that same info in the body?

    def foo(a, b, c):
       params = [a, b, c]
    

    What have I missed?

    0 讨论(0)
  • 2020-12-01 14:18

    You can use the inspect module:

    def foo(x):
        return x
    
    inspect.getargspec(foo)
    Out[23]: ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None)
    

    This is a duplicate of this and this.

    0 讨论(0)
提交回复
热议问题