For a project, I've been storing data in a text document and I've noticed a problem when trying to receive that data back within the script. More specifically I'm using the readlines() method to get the data. When I use it the first time, it works just fine; however, any time after that it returns an empty list despite nothing in the document changing.
I've replicated the problem with this small chunk of code:
testDocRead = open("C:\\Users\\emowe\\OneDrive\\Desktop\\Python\\testDocument.txt", "r")
print(testDocRead.readlines()) # attempt 1
print(testDocRead.readlines()) # attempt 2
On the first attempt, everything works as intended. It prints:
['Filler\n', 'text\n', 'to\n', 'add\n', 'lines']
The second attempt simply prints:
[]
My questions are:
- Why is this happening?
- How do I update the value without nothing being returned?