title: How to reset a variable assigned to function in Python 2.73?
body: <p>so basically a guy helped me improve my code. The problem is, it's still dead disappointing and does not work. What I wanna do, is reset the lenRecur.number so I could use the function again, using other strings and getting correct answers (not too big answers)</p>
  
  <p>I guess, the problem is with hasattr. But I can't remove it, because if I do, my string length calculator won't work.</p>
  
  <p>Anyway, even if I add lenRecur.number = 0 after the function, it still doesn't work.</p>
  
  <p>It's like impossible, because when the function hits "return", it's done, period. If I reset it before "return", it will return 0, not correct answer so yeah I'm in deep trouble here.</p>
  
  <pre><code>def lenRecur(aStr):
      if not hasattr(lenRecur, 'number'):
          lenRecur.number = 0
      '''
      aStr: a string
  
      returns: int, the length of aStr
      '''
      if aStr == '':
          return lenRecur.number
      else:
          lenRecur.number += 1
          return lenRecur(aStr[:-1])
  </code></pre>
  
  <p>P.s. the goal of my program(?) / script(?) is to measure the length of input string, without using input() method. As trying to re-create the length() method, with using more primitive means.</p>
  
  <p>The script will have to have many different inputs, so it shall reset.</p>