I have following file structure:
proj
- __init__.py
- bar.py # contains constant 'foo', used in consumers of proj
Now I have realised bar.py
fits nicely in a subfolder. However I need to make this change without changing the code depending on proj
. Specifically, from proj.bar import foo
should still work. So I'm changing the file structure to:
proj
- __init__.py
- subfolder
- - bar.py
I have tried to put from .subfolder import bar
into __init__.py
. However, following error occurs:
import proj
print(proj.bar) # <module 'proj.subfolder.bar' from '~/proj/subfolder/bar.py'>
from proj.bar import foo # ModuleNotFoundError: No module named 'proj.bar'
What can I put in __init__.py
of proj such that any consumer can still do from proj.bar import foo
?