title: Python - local variable referenced before assignment
body: <p>I am relatively new to programming and I am suffering from what appears to be a simple problem.</p>
  
  <p>Here's the snippet that is causing the problem (it is part of this larger function: <a href="http://pastebin.com/2apwWsEv" rel="nofollow">http://pastebin.com/2apwWsEv</a>):</p>
  
  <pre><code>for i in range(4,12):                       # remove nulls
      if not row[i]:
          row[i] = False
      if row[i] and (i % 2):                          # odd rows (time)
          print row[i]
          time = row[i].split(':')
          row[i] = int(time[0]) * 3600 + int(time[1]) * 60 + int(time[2])
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>row[i] = int(time[0]) * 3600 + int(time[1]) * 60 + int(time[2])
  UnboundLocalError: local variable 'time' referenced before assignment
  </code></pre>
  
  <p>It seems I assigned <code>time</code> the value of <code>row[i].split(':')</code>, so I do not understand where the error is.</p>
  
  <p>I tried changing around the second <code>if</code> statement (to a more conventional <code>elif</code>, etc) but that did not change the error.</p>
  
  <p><em>(The time field, of the csv data, is in the format of hh:mm:ss and I am trying to convert it to seconds.)</em></p>
  
  <p>Can someone please explain how <code>time</code> is being used before it is assigned?</p>