title: Creating a counter inside a Python for loop
body: <p>Obviously, if we do this, the counter will remain at 0 as it is reset at the start of every iteration:</p>
  
  <pre><code>for thing in stuff:
      count = 0
      print count
      count =+1
      write_f.write(thing)
  </code></pre>
  
  <p>But as I have this code inside of function, it does not work to do this either:</p>
  
  <pre><code>count=0
  for thing in stuff:
      print count
      count =+1
      write_f.write(thing)
  </code></pre>
  
  <p>I have several different indent levels, and no matter how I move <code>count=0</code>about, it either is without effect or throws <code>UnboundLocalError: local variable 'count' referenced before assignment</code>. Is there a way to produce a simple interation counter just inside the for loop itself?</p>