I've been trying to figure out how to call a module after importing its parent package.
The directory structure looks like:
.
├── main
│ └── pkg
│ └── file.py
└── another_main
NOTE: All the packages contain __init__.py file and all the necessary path variables are set. I've not shown it here as this is just a dummy structure.
If I do:
from main import pkg
pkg.file
This doesn't work and throws AttributeError: module 'pkg' has no attribute 'file'
But if first I do:
from main.pkg import file
After that I can do:
from main import pkg
pkg.file # --> Now this doesn't throw AttributeError
Is there a way I can call file like pkg.file without doing from main.pkg import file?
P.S.: I want to use pkg.file in my script so that in future I can recall that I called file from pkg and not some_other_pkg.