I am new to Pytho. I am using it to read a large file. To do this, I am using the file object as iterator as specified in the sixth answer here by jyoti das: How can I read large text files in Python, line by line, without loading it into memory?
My code:
with open(filename, 'r', buffering=100000) as f:
time_data_count = 0
for line in f:
if 'TIME_DATA' in f:
time_data_count += 1
if time_data_count > 20:
print("time_data complete")
else:
print("incomplete time_data data")
However, my code only reads the first line of the file and then exists the loop so time_data_count stays at 0. Why is this?
I have tried stepping into the code but I don't see why it only stops at first line