3 ms·
(Can we avoid the editorialized titles?) Relative imports and mucking with sys.path should be avoided. This StackOverflow answer is providing the right recomme
by techwizrd 3y ago
(Can we avoid the editorialized titles?)
Relative imports and mucking with sys.path should be avoided. This StackOverflow answer is providing the right recommendation: make your code into a library. You can do this via pyproject.toml or setup.py, and it's really quite painless. The sooner you do so, the easier things will be.
If you really just want to hack something together (and aren't planning on sharing the code with anyone), you can use importlib to import a Python source file directly [0].
0: https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly https://docs.python.org/3/library/importlib.html#importing-a...