Hi
I have the following 2 threads in a python script
The first thread writes to a file and the 2nd reads the same file and checks for 'My Word' I am trying to replace the file.txt with a new file.txt after the time.sleep(2) by the doing the following
But i'm getting the following error
Unhandled exception in thread started by <function wordcount at 0x00BA0030>
Traceback (most recent call last):
File "keep.py", line 18, in wordcount
word.close()
NameError: global name 'word' is not defined
Has anyone got any ideas why this is happening?
Thanks
I have the following 2 threads in a python script
Code:
def recv_pkts(hdr, data): tmp= sys.stdout x = EthDecoder().decode(data) sys.stdout = open('c:\\scripts\\file.txt', 'a') print x while 1: Word = open('c:\\scripts\\file.txt').read() v = Word.count('My Word') if v > 2: print "Word Here" time.sleep(2)
Code:
Word = open('c:\\scripts\\file.txt').read() v = Word.count('My Word') if v > 2: print "Word Here" time.sleep(2) word.close() temp = open(c:\\scripts\\file.txt','w') temp.close()
Unhandled exception in thread started by <function wordcount at 0x00BA0030>
Traceback (most recent call last):
File "keep.py", line 18, in wordcount
word.close()
NameError: global name 'word' is not defined
Has anyone got any ideas why this is happening?
Thanks
Comment