Jim*_*ies 7 python parameters arguments introspection partial
我正在寻找类似于这里所要求的东西获取python函数内的参数名列表,但使用部分函数.即.我需要获得部分函数的可能参数.我可以使用以下方法获取关键字参数
my_partial_func.keywords
Run Code Online (Sandbox Code Playgroud)
但我目前正在努力获得非关键字参数.检查模块也没有为这种特殊情况产生任何结果.任何建议都会很棒.
.args
包含传递给偏函数的参数。如果您想获得原始函数期望的参数,请使用inspect
您在.func
属性上链接的解决方案。
您可以通过调用dir
functools.partial 对象来找到这一点:
>>> dir(x)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'args', 'func', 'keywords']
Run Code Online (Sandbox Code Playgroud)