Let me ask the question by a simplified example. Assume I have a python2 script called example.py in a directory with other script I wrote called utils.py. In example.py, I need to import an external module which is placed under the path /A/B/external.py. 'A' and 'B' are just folders, not packages (without __ init__.py). Finally, assume that there is a utils.py file under /A/B/ as well, and it is imported by external.py.
If I import the external module by the way I'm familiar with, I'll do:
import sys sys.path.append('/A/B/') import external the problem is that when I'll try to import my utils module, python will find it in sys.modules dict (since external imported it) and thus won't import my script but only the one under /A/B which was already imported.
Now, there are workarounds. I may change the name of the module, or put the external module in a package, etc. But all of these feel dirty. I couldn't find what is the 'pythonic' best practice to do such things. As some of you might guess, it could lead to very annoying bugs with more complex cases. In addition, the way I'm familiar with is not acceptable by PEP8 as there are import commands not at the top of the module.
In conclusion, I'm looking for the best practice to do such things, thanks.