Python: how to open files from another directory git repo (locally cloned)?

Viewed 44

I'm currently working on a Python module in a git repo and need to read files from another directory in the same repo. I have the repo cloned locally, so my module can currently open local files saved in the same directory as my module, but I need to be able to open other files from other directories within the same repo. What's the best way I can do this? Thanks so much for any help!

1 Answers

Here's how we do it where I work!

Lets say the directory looks like so:

User -|
      |-GitHub/-
               |- dir_1/
               |
               |- dir_2/ -
                        |- module_path_1/ -
                                        | - module.py

We are in dir_1, running our code from dir_1.

import sys
sys.path.append("../dir_2/module_path_1")
from module import function1

And that should do it!

Related