environment windows7 (I want a Mac Book Pro 16inch) Visual Studio Code chrome
This article is written for beginners in programming and Python.
When I try to read a text file with the python file I'm working on, I get an error saying No such file or directory:
and I can't read the text file.
4 hours to fight ...
It came to a solution.
file.py
f = open("trial_data.txt")
print(f.read())
f.close()
#FileNotFoundError: [Errno 2] No such file or directory: 'trial_data'
Gabyen! !! !! is. It's been 4 hours since I knocked it down.
current directory
I noticed that. It is "google in python current directory" on the question site. This one word led to a solution.
file.py
import os
currentdir = os.getcwd()
print(currentdir)
#C:\Users\(username)
So put trial_data in C: \ Users \ (username) and it's solved.
It was an embarrassing skill for PC beginners and programming beginners ...
Fin
Recommended Posts