+2 votes
in Programming Languages by (7.8k points)
I have a dynamic file wherein records are being continuously added. I have to read this file and based on a particular record, I have to trigger an event. How can I implement this?

1 Answer

0 votes
by (15.1k points)

Have a look at the following example. Suppose my test.txt file has the following content and it's a dynamic file.

abc
def
ghi
jkl
mno
324q23
234532
2345325

and I want my code to perform some operation if it sees '12345' in the input file.

found=0
f=open('test.txt' ,'r')
while not found:
        cp = f.tell()
        line = f.readline()
        if not line.strip():
                f.seek(cp)
        elif '123456' in line:
                print(line.strip())
                #do something

...