Python Forum
Why it does not print(file.read())
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why it does not print(file.read())
#1
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.
Yoriz write Jul-01-2021, 11:18 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Larz60+ write Jul-01-2021, 11:18 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Pleas do not use images for code. Fixed for you this time, please use bbcode tags on future posts.
Reply
#2
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.
Rejaul84 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Read csv file through PyCharm kimx0961 3 438 Aug-01-2021, 07:05 PM
Last Post: perfringo
  Read and write active Excel file euras 4 530 Jun-29-2021, 11:16 PM
Last Post: Pedroski55
  [Solved] Trying to read specific lines from a file Laplace12 7 769 Jun-21-2021, 11:15 AM
Last Post: Laplace12
  [Solved] Using readlines to read data file and sum columns Laplace12 4 509 Jun-16-2021, 12:46 PM
Last Post: Laplace12
  Read file, reformat and write new file bryanmartin113 1 512 Jun-08-2021, 09:27 PM
Last Post: Larz60+
  failing to print not matched lines from second file tester_V 13 1,511 Apr-13-2021, 03:36 PM
Last Post: DeaD_EyE
  Read/Write binary file deanhystad 3 931 Feb-01-2021, 10:29 AM
Last Post: Larz60+
  how to change the range of read CSV file every time python file runs greenpine 6 997 Dec-08-2020, 10:11 PM
Last Post: greenpine
  How to read CSV file one row at the time in a range and some delay in between greenpine 2 1,505 Nov-20-2020, 02:26 PM
Last Post: greenpine
  get two characters, count and print from a .txt file Pleiades 9 1,104 Oct-05-2020, 09:22 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020