Open files through the relative directory

Asked

Viewed 486 times

0

How do I read the relative file path that is in a different python file directory and then open that file?

For example: For archive1 in the name_project/files/file1.txt directory and the python code in the name_project/srcfunction directory os.path.relpath me returns file1.txt as relative path and the open function generates an exception of IOError.

  • Want to open a python file or read the file in another directory?

  • Read file in another directory

  • I’ve reread the question a few times and I couldn’t understand what was asked. If you know where the file is regarding your code, what exactly do you need to do? If your code is on srcfuncão, just open the file arquivos/arquivo1.txt.

  • It’s just an example. I just wanted to say that the file and the code are in different directories

  • How are you trying to do ? You can put the code ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.