I had a script which I developed in /var/tmp and worked… when I moved to the required directory for some reason it returns the following error:
Traceback (most recent call last):
File "tail.py", line 104, in <module>
test=isItAlive(line)
File "tail.py", line 55, in isItAlive
return test
UnboundLocalError: local variable 'test' referenced before assignment
The function it is moaning about is:
def isItAlive(text):
with open(valcsv) as f:
searches = [x.split(',')[1] for x in f.read().splitlines()]
for search in searches:
# print search
if not search in text:
test="TOBEADDED"
else:
test=search
break
return test
f.close()
Your
searchesvalue is empty, so theforloop never assigns a value totest.Initialize
testat the start of your function:and figure out why your
valcsvfile is empty.