title: UnboundLocalError: local variable 'i' referenced before assignment
body: <p>I keep getting this annoying error, no clue how to solve it.</p>
  
  <p>I'm trying to open a txt file with a for statement:</p>
  
  <pre><code>def file_len(fname):
      with open(fname) as f:
          for i, l in enumerate(f):
              pass
      return i + 1
  </code></pre>