Answer the question
In order to leave comments, you need to log in
How to correctly set the path to a file in python?
I know this is a stupid question, but always, open a file like this: cd Desktop and the next command was python3 (filename with extension .py)
started going through the topic of files where you can open, like
F = open('filename with extension'), what does he give me
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'kl.py'
Answer the question
In order to leave comments, you need to log in
how to correctly set the path to the file in the command F = open("") without resorting to clumsy cd?
with open(os.path.join('Desktop', 'kl.py')) as f:
pass
C:\Desktop\project
├── abc.txt
├── main.py
├── folder
└── xyz.txt
C:\Desktop\project\abc.txt
, C:\Desktop\project\folder\xyz.txt
, abc.txt
, folder\xyz.txt
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question