Python函数的参数长度? [英] Length of arguments of Python function?
本文介绍了Python函数的参数长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
如何在蟒蛇
例如我声明了一个函数:
For example I have declared a function:
def sum(a,b,c):
return a + b + c
我想获取sum"函数的参数长度.
像这样:some_function(sum) 返回 3
在Python中如何实现?
I want to get length of arguments of "sum" function.
somethig like this: some_function(sum) to returned 3
How can it be done in Python?
更新:
我问这个问题是因为我想写一个函数,它接受另一个函数作为参数和参数来传递它.
Update:
I asked this question because I want to write a function that accepts another function as a parameter and arguments to pass it.
def funct(anotherFunct, **args):
我需要验证:
if(len(args) != anotherFuct.func_code.co_argcount):
return "error"
推荐答案
如果你的方法名称是 sum
那么 sum.func_code.co_argcount
会给你参数的数量.
If your method name is sum
then sum.func_code.co_argcount
will give you number of arguments.
这篇关于Python函数的参数长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文