So, I have this python thing that should handle the file.
At first it was:
my_project/ ├── script.py
And I just run it with python script.py file.csv .
Then he grew and became:
my_project/ ├── script.py ├── util/ │ └── string_util.py ├── services/ │ └── my_service.py
(Each directory has an empty __init__.py )
But now my_service.py would like to use string_util.py , and it is not so simple just how to do this. p>
I would like to do from ..util import string_util in my_service.py (which is imported into script.py using from services import my_service ), but this does not work with python script.py , since my_service __name__ now only services.my_service (and I get Attempted relative import beyond toplevel package )
I can do cd .. and python -m my_project.script , but it seems so unnatural, and it would be very difficult to put it in README for instructions on how to run it.
Now I solve it with an ugly hack sys.path.append() .
What other options do I have?
python module package python-import project-structure
Bloke
source share