Reading a file in Python

Hello everyone, newbie to this forum AND Python. I have been watching a 4-hour youtube video that has been of great help however, one of the topics covered is “Reading a file”. I have written my program the exact same way as the instructor however, mine isn’t reading the file, like his does. I have created a .txt file, mapped it to a variable in the PyCharm IDE like so:

employee_file = open(“employees.txt”, “r”)

all it displays is “Process finished with exit code 0”. When I execute a “readable” instruction it returns a “True” so I am not sure what I am doing wrong. Thank you

What did you put inside of the employees.txt file? If there isn’t anything there, there’s nothing to print.

Okay, this is embarrassing. It started out with a filename of “scratch”. I renamed it “employees”. Apparently, after refactoring, it removed all of the data I had input into it so yes, it was empty. Sorry about that, and thank you.

Hey, its happens to all of us : )

1 Like