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
  Saving the print result in a text file Calli 8 219 Sep-25-2022, 06:38 PM
Last Post: snippsat
  read a text file, find all integers, append to list oldtrafford 12 743 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  Read xml column inside csv file with Python estertabita 2 402 Jul-26-2022, 06:09 PM
Last Post: Larz60+
  failing to print not matched lines from second file tester_V 14 3,654 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  Print to a New Line when Appending File DaveG 0 459 Mar-30-2022, 04:14 AM
Last Post: DaveG
Question How do I skipkeys on json file read to python dictionary? BrandonKastning 3 829 Mar-08-2022, 09:34 PM
Last Post: BrandonKastning
Sad Want to Save Print output in csv file Rasedul 5 3,000 Jan-11-2022, 07:04 PM
Last Post: snippsat
  Error When Trying To Read CSV File kaega2 3 1,956 Dec-03-2021, 09:10 PM
Last Post: kaega2
  Convert legacy print file to XLSX file davidm 1 997 Oct-17-2021, 05:08 AM
Last Post: davidm
  [SOLVED] Read text file from some point till EOF? Winfried 1 952 Oct-10-2021, 10:29 PM
Last Post: Winfried

Forum Jump:

User Panel Messages

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