Seb_
Seb_

Reputation: 35

Python not reading last line from file

I pull some data from DB and save it to a text file called "databaseoutput.txt". When I run the code below all lines are displayed except the last one - and I know it's there because when I open the file the line that's missing when I run the code below is present

with open("databaseoutput.txt", 'r', encoding='utf-8') as f:
    for line in f:
        print(line)

What can be causing this?

Upvotes: 0

Views: 765

Answers (1)

celw10
celw10

Reputation: 11

I just had the same problem as you. When creating my text file I forgot to close it with:

f.close()

Upvotes: 1

Related Questions