Jun-11-2023, 07:55 AM
(This post was last modified: Jun-11-2023, 07:55 AM by deanhystad.)
That's odd. I ran this program:
I get the same behavior if I run this program.
with open("output.txt", "r") as file: for last_line in file: pass while True: for new_line in file: if 'Driver not connected' in new_line or 'Data stale' in new_line: print("Starting the driver")Then I opened the file "output.txt", typed 'Driver not connected', and saved the file. The program promptly prints "Starting the driver" one time. I wait a while to see if this is printed again. It does not. Only once. So I append 'Driver not connected' to the output.txt and save the file. The program promptly prints "Starting the driver" one time.
I get the same behavior if I run this program.
# Get pointer to end of file with open("output.txt", "a") as file: fp = file.tell() while True: with open("output.txt", "r") as file: file.seek(fp) for line in file: if 'Driver not connected' in line or 'Data stale' in line: print("Starting the driver") fp += len(line)Each program only prints the line once when I add a line to the file. What happens if you run the program on your computer? Does it behave the same?