title: Local variable referenced before assignment?
body: <p>I am using the PyQt library to take a screenshot of a webpage, then reading through a CSV file of different URLs. I am keeping a variable feed that incremements everytime a URL is processed and therefore should increment to the number of URLs.</p>
  
  <p>Here's code:</p>
  
  <pre><code>webpage = QWebPage()
  fo = open("C:/Users/Romi/Desktop/result1.txt", "w")
  feed = 0
  def onLoadFinished(result):
      #fo.write( column1[feed])#, column2[feed], urls[feed])
     #feed = 0
     if not result:
          print "Request failed"
      fo.write(column1[feed])
      fo.write(',')
      fo.write(column2[feed])
      fo.write(',')
      #fo.write(urls[feed])
      fo.write(',')
      fo.write('404,image not created\n')
      feed = feed + 1
          sys.exit(1)
          save_page(webpage, outputs.pop(0))   # pop output name from list and save
     if urls:
          url = urls.pop(0)   # pop next url to fetch from list
          webpage.mainFrame().load(QUrl(url))
      fo.write(column1[feed])#,column2[feed],urls[feed],'200','image created','/n')
      fo.write(',')
      fo.write(column2[feed])
      fo.write(',')
      #fo.write(urls[feed])
      fo.write(',')
      fo.write('200,image created\n')
      feed = feed + 1
     else:
          app.quit()  # exit after last url
  
  webpage.connect(webpage, SIGNAL("loadFinished(bool)"), onLoadFinished)
  webpage.mainFrame().load(QUrl(urls.pop(0)))
  #fo.close()
  sys.exit(app.exec_())
  </code></pre>
  
  <p>It gives me the error:</p>
  
  <pre><code>local variable feed referenced before the assignment at fo.write(column1[feed])#,column2[feed],urls[feed],'200','image created','/n')
  </code></pre>
  
  <p>Any idea why?</p>