+2 votes
in Programming Languages by (73.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

+1 vote
by (349k points)
selected by
 
Best answer

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

Related questions

+2 votes
1 answer
+1 vote
1 answer
+5 votes
1 answer

...