Modules have a magic attribute called __path__. Whenever you'r | Python etc
Modules have a magic attribute called __path__. Whenever you're doing subpackage imports, __path__ is being searched for that submodule.
__path__ looks like a list of path strings, e.g ["foo/bar", "/path/to/location"].
So if you do from foo import bar, or import foo.bar, foo's __path__ is being searched for bar. And if found - loaded.
You can play around with __path__ to test it out.
Create simple Python module anywhere on your system:
$ tree . └── foo.py
$ cat foo.py def hello(): return "hello world"
Then, run the interpreter there and do the following: python >>> import os >>> os.__path__ = ["."] >>> from os.foo import hello >>> hello() 'hello world'
As you can see, foo is now available under os: python >>> os.foo