You can import /shared using parent module, as long as the parent module is in PYTHONPATH. If your project would look like:
toplevel_package/
├── __init__.py
├── main.py
└── project1
├── __init__.py
└── foo.py
└── project2
├── __init__.py
└── bar.py
└── shared
├── __init__.py
└── save_files.py
Then imports would look like:
from toplevel_package.shared import save_files
This works as long as toplevel_package is in your PYTHONPATH. Either:
- onlyOnly launch toplevel_package skriptsscripts (which can then call subpackages)
- moveMove toplevel_package module to any folder listed in PYTHONPATH
- addAdd toplevel_package to PYTHONPATH
More info can be found in import from parent.
You could also simply use import using full path, which is not as pythonic in my opinion but works well in some situations (in the end, .
You can import /shared using parent module, as long as the parent module is in PYTHONPATH. If your project would look like:
toplevel_package/
├── __init__.py
├── main.py
└── project1
├── __init__.py
└── foo.py
└── project2
├── __init__.py
└── bar.py
└── shared
├── __init__.py
└── save_files.py
Then imports would look like:
from toplevel_package.shared import save_files
This works as long as toplevel_package is in your PYTHONPATH. Either:
- only launch toplevel_package skripts (which can then call subpackages)
- move toplevel_package module to any folder listed in PYTHONPATH
- add toplevel_package to PYTHONPATH
More info can be found in import from parent.
You could also simply use import using full path, which is not as pythonic in my opinion but works well in some situations (in the end, .
You can import /shared using parent module, as long as the parent module is in PYTHONPATH. If your project would look like:
toplevel_package/
├── __init__.py
├── main.py
└── project1
├── __init__.py
└── foo.py
└── project2
├── __init__.py
└── bar.py
└── shared
├── __init__.py
└── save_files.py
Then imports would look like:
from toplevel_package.shared import save_files
This works as long as toplevel_package is in your PYTHONPATH. Either:
- Only launch toplevel_package scripts (which can then call subpackages)
- Move toplevel_package module to any folder listed in PYTHONPATH
- Add toplevel_package to PYTHONPATH
More info can be found in import from parent.
You could also simply use import using full path, which is not as pythonic in my opinion but works well in some situations (in the end, .
You can import /shared using parent module, as long as the parent module is in PYTHONPATH. If your project would look like:
toplevel_package/
├── __init__.py
├── main.py
└── project1
├── __init__.py
└── foo.py
└── project2
├── __init__.py
└── bar.py
└── shared
├── __init__.py
└── save_files.py
Then imports would look like:
from toplevel_package.shared import save_files
This works as long as toplevel_package is in your PYTHONPATH. Either:
- only launch toplevel_package skripts (which can then call subpackages)
- move toplevel_package module to any folder listed in PYTHONPATH
- add toplevel_package to PYTHONPATH
More info can be found in import from parent.
You could also simply use import using full path, which is not as pythonic in my opinion but works well in some situations (in the end, .