Python Forum
Why it does not print(file.read()) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Why it does not print(file.read()) (/thread-34159.html)



Why it does not print(file.read()) - Rejaul84 - Jul-01-2021

I am a total beginner and not sure why it not printing what I have written to the data.csv file. I can see the data in the csv but expected python to have printed what I have written.

Please see the image that I've attached showing my code.


RE: Why it does not print(file.read()) - bowlofred - Jul-01-2021

Please post your code as text (using the python tags or buttons in the editor), not as images.

An open file only has one file pointer. If you open a file for both reading and writing and you write 200 bytes of encoded data, the file pointer will be at byte 200 of the file.

If you then attempt to read with nothing else done, you will be reading from that point in the file. If there is no more data past that point, then the read() will return an empty string.

You can reset back to the beginning by closing and re-opening the file, or by calling seek() method on the file.