Python的函数的参数长度? [英] Length of arguments of Python function?
问题描述
可能重复:结果
如何找出一个方法在元数Python的
块引用>例如我宣布一个函数:
DEF总和(A,B,C):
返回+ B + C我想要得到的求和函数的参数长度。
somethig是这样的:some_function(总和)退换3
如何可以把它在Python做呢?更新:的
因为我想写一个接受另一个函数作为参数,参数的函数通过它我问这个问题。高清FUNCT(anotherFunct,**参数):
和我需要验证:
IF(LEN(参数)= anotherFuct.func_ code.co_argcount!):
回归错误
解决方案如果您的方法名称为
之
然后sum.func_ code .co_argcount
会给你的参数个数。Possible Duplicate:
How to find out the arity of a method in PythonFor example I have declared a function:
def sum(a,b,c): return a + b + c
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):
and I need to validate:
if(len(args) != anotherFuct.func_code.co_argcount): return "error"
解决方案If your method name is
sum
thensum.func_code.co_argcount
will give you number of arguments.这篇关于Python的函数的参数长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!