title: How to count function calls using decorators?
body: <p>I'm refreshing my memory about some python features that I didn't get yet, I'm learning from <a href="http://www.python-course.eu/python3_decorators.php" rel="noreferrer">this python tutorial</a> and there's an example that I don't fully understand. It's about a decorator counting calls to a function, here's the code:</p>
  
  <pre><code>def call_counter(func):
      def helper(x):
          helper.calls += 1
          return func(x)
      helper.calls = 0
      return helper
  
  @call_counter
  def succ(x):
      return x + 1
  
  if __name__ == '__main__':
      print(succ.calls)
      for i in range(10):
          print(succ(i))
      print(succ.calls)
  </code></pre>
  
  <p>What I don't get here is why do we increment the calls of the function wrapper (helper.calls += 1) instead of the function calls itself, and why does it actually working? </p>