如何计算函数中的变量数-Python

如何计算函数中的变量数-Python,python,function,arguments,decorator,counting,Python,Function,Arguments,Decorator,Counting,我希望能够编写一个计算函数中参数数量的函数,例如: 柜台(“一”、“二”) 二, 柜台(“一”、“二”、“三”) 三, 等等, 到目前为止我已经知道了,但我不确定它是否正确。有人能帮我解决这个问题吗?谢谢 def counter(f): f.counter = 0 def counting_f(*args): v = f(*args) f.counter += 1 print("{0}: {1} times".format(f.__

我希望能够编写一个计算函数中参数数量的函数,例如:

柜台(“一”、“二”)

二,

柜台(“一”、“二”、“三”)

三,

等等,

到目前为止我已经知道了,但我不确定它是否正确。有人能帮我解决这个问题吗?谢谢

def counter(f):
    f.counter = 0
    def counting_f(*args):
        v = f(*args)
        f.counter += 1
        print("{0}: {1} times".format(f.__name__, f.counter))
        return v
    return counting_f

不知道你想要什么。是这样吗

def counter(*f):
  print len(f)

>>> counter("one", "two")
2

>>> counter("one", "two","three")
3