I have also tried searching for the answer but I don't understand the answers to other people's similar problems...
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) <= 0.1
and abs(float(data[1]) - breq) <= 0.1):
T= data[2]
return T
print temp_sky(60, 60)
print temp_sky(10, -10)
I get the following error
7.37052488
Traceback (most recent call last):
File "tsky.py", line 25, in <module>
print temp_sky(10, -10)
File "tsky.py", line 22, in temp_sky
return T
UnboundLocalError: local variable 'T' referenced before assignment
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!