title: How to count the number of variables in a function - Python
body: <p>I want to be able to write a function that counts the number of arguments in a function, for example:</p>
  
  <blockquote>
    <blockquote>
      <blockquote>
        <p>counter("one", "two")</p>
        
        <p>2</p>
        
        <p>counter("one", "two", "three")</p>
        
        <p>3</p>
      </blockquote>
    </blockquote>
  </blockquote>
  
  <p>etc,</p>
  
  <p>I have this so far but I'm not sure it's right. Could someone help me out with this please? Thanks.</p>
  
  <pre><code>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
  </code></pre>