python UnboundLocalError: local variable referenced before assignment
<p>I have also tried searching for the answer but I don't understand the answers to other people's similar problems...</p>

<pre><code>tfile= open("/home/path/to/file",'r') 

def temp_sky(lreq, breq):
    for line in tfile:
        data = line.split()
        if ( abs(float(data[0]) - lreq) &lt;= 0.1 and abs(float(data[1]) - breq) &lt;= 0.1):            
            T= data[2]
    return T
print temp_sky(60, 60)
print temp_sky(10, -10)
</code></pre>

<p>I get the following error </p>

<pre><code>7.37052488
Traceback (most recent call last):
File "tsky.py", line 25, in &lt;module&gt;
  print temp_sky(10, -10)
File "tsky.py", line 22, in temp_sky
  return T
UnboundLocalError: local variable 'T' referenced before assignment
</code></pre>

<p>The first print statement works correctly but it won't work for the second. I have tried making T a global variable but this makes both answers the same! Please help! </p>
