Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Read File Issue
#1
Hi,
So basically i'm trying to read something from a simple text file, and i don't really get any errors but the output is blank. Any help is appreciated :-)

employee_file = open("asa.txt", "r")

print(employee_file.read())

employee_file.close()
Output:
Process finished with exit code 0
Reply
#2
maybe the text file is empty?
Reply
#3
It's not...

Dammit i guess it's a unique problem only on my computer, i have tried with 3 diffrent text files, still same result.. Also i have tried to "r+" and "w" still..
Reply
#4
Did you start the script in the same directory that contains the text file?

You can try the full path

employee_file = "/Path/To/asa.txt"
with open(employee_file, 'r') as f:    
    print(f.read())
Reply
#5
I just fixed it :D. The problem was with the software and not the actual code. I do not know why?? But after installing Submlime Text everything worked perfectly fine, i used PyCharm before. So weird... It should work either way. Thank u so much for trying to help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved] Using readlines to read data file and sum columns Laplace12 4 94 11 hours ago
Last Post: Laplace12
  Read file, reformat and write new file bryanmartin113 1 201 Jun-08-2021, 09:27 PM
Last Post: Larz60+
  Read/Write binary file deanhystad 3 535 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 597 Dec-08-2020, 10:11 PM
Last Post: greenpine
  Using a .bat file to execute simple anaconda commands in Windows 10 gacg1 0 558 Nov-30-2020, 03:24 PM
Last Post: gacg1
  How to read CSV file one row at the time in a range and some delay in between greenpine 2 679 Nov-20-2020, 02:26 PM
Last Post: greenpine
  can't read QRcode in large file simoneek 0 487 Sep-16-2020, 08:52 AM
Last Post: simoneek
  Binary File Read Aussie 6 1,577 Sep-03-2020, 03:57 AM
Last Post: deanhystad
  Simple plotting from txt file Laplace12 2 541 Aug-23-2020, 09:58 AM
Last Post: Laplace12
  Read strings and numbers in columns from a file suvadip 4 887 Aug-11-2020, 09:37 PM
Last Post: suvadip

Forum Jump:

User Panel Messages

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