I've been testing reading lines from a text file and finally got my program to execute correctly. But I'm not sure why the while
loop exits execution.
filepath = 'LastQuizPlan.txt'
with open(filepath) as fp:
line = fp.readline()
count = 1
while line:
print(line.strip)
line=fp.readline()
count+=1
I found the code online from http://stackabuse.com/read-a-file-line-by-line-in-python/ and manipulated it slightly, it works fine but i need to create a write up for it as well and dont know how the while line:
works exactly? it works exactly as i want it to work but i dont understand what its expression is.
I've been using the following statement for trying to figure this out
while expression:
statement(s)
but still just dont understand the expression? why does it automatically know that when count is out of the range of lines in "LastQuizPlan.txt", to stop the loop.
also here is the contents of "LastQuizPlan.txt" Unit 1 Electrical stuff 12/06/17