I've got a directory structure like:
Folder_in_PYTHONPATH/
├── Package1
│ ├── __init__.py
│ ├── src
│ │ ├── Class1.py
│ │ ├── Class2.py
│ │ └── __init__.py
│ └── test
│ └── testfile.py
├── Package2
│ ├── __init__.py
│ ├── src
│ │ ├── Class1.py
│ │ ├── Class2.py
│ │ └── __init__.py
│ └── test
│ ├── test1.py
│ └── test2.py
.
.
.
When I import things from this folder, I need to always type
import Package1.src.Class1
Is there any way to set up my __init__.py
so that I can just type
import Package1.Class1
instead?
Add them into your packages' __init__.py
files so they look like:
from src import Class1
from src import Class2
Have a look at the docs
I would recommend putting the *.py files in the top level folder of their package to get the import Package_1.Class1
behaviour you are after. The unit tests can stay in their own folder to keep them separate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With