So I am writing a for loop program which reads line from the file.
file lines looks like this:
Program: Python User: Cma Code: 1234
The program goes like this:
while True:
with open('file.txt', 'r') as fp:
for i in fp:
data = i.split()
program = data[1]
user = data[3]
code = data[5]
total = program + user + code
print(total)
file.seek(-len(i),1)
else:
print("Program Put to sleep!")
time.sleep(5)
I believe my issue in this code is a logical error. The program is suppose to keep running and check of the file constantly. If there are 3 lines in the file it should read each one of them then unread it and when it finds there is no more lines in the file, the program goes to sleep and and start the loop from the new line entry.
In the program I have coded it keeps on reading from the beginning. Had a look at some examples from this platform but wasn't helpful so thought to ask. cheers