I'm unsure how you are supposed to work with a large local codebase in Python when it comes to imports.
After years of using Python, I really need to learn this. Please help.
Consider the following totaly vanilla project structure:
project/
|- webapp/
| |- app.py
|
|- notebooks/
| |- analysis.ipynb
|
|- src/
|- __init__.py
|- utils.py
|- database.py
How are you supposed to cross import all these files?
If database has a dependency on my_helper
from utils
, should it include
from .utils import my_helper
Or from utils import my_helper
, or from src.utils import my_helper
And what if these files are not adjacent to each other in the file system (eg. they are in different folders).
And what about importing from these files in the notebook folder? Is sys.path
hi-jinks the best solution? What about the app.py
file? What if it has a dependency on database.py
?
Has the Python world reached a consensus on this?