Importing From Sister Subdirectories in Python?
import, python
Solution
The simplest solution is to put the directory containing `repo` in your `PYTHONPATH`, and then just use absolute-path imports, e.g. `import repo.sub2.mod2` and so on.
Any other solution is going to involve some hackery if you want it to cover cases where you're invoking both the python files directly as scripts from arbitrary directories - most likely `sys.path` mangling to effectively accomplish the same thing as setting `PYTHONPATH`, but without having to have the user set it.
Problem
So, I've seen a few similar questions on Stack Overflow, but nothing seems to address my issue, or the general case. So, hopefully this question fixes that, and stops my headaches. I have a git repo of the form: ``` repo/ __init__.py sub1/ __init__.py sub1a/ __init.py mod1.py sub2/ __init__.py mod2.py ``` How do I import mod2.py from mod1.py and vice versa, and how does this change depending on whether mod1.py or mod2.py are scripts (when each respectively is importing-- not being imported)?