T
T
toshk92020-08-28 12:40:05
Python
toshk9, 2020-08-28 12:40:05

In what directory should files be stored for their opening and further reading through open, read, etc.?

The text file that I want to read in Python is stored in the same directory as the program in which I want to open and read the same text file, but when I run the program, I get the error No such file or directory: 'text.txt' 5f48d0dda345a192009243.jpeg5f48d0bbcae3a228831743.jpeg5f48d0e5cde19367983847.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-08-28
@toshk9

At any. You are most likely running from a different directory.

import os
file_path = os.path.join(os.getcwd(), 'text.txt')
f = open(file_path)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question