I am trying to understand how a lower level package 'knows' about a higher level module such that calling it doesn't result in an error. My directory structure is as follows:
.
├── foo.py
├── script.py
├── pkg
│ ├── __init__.py
My file contents are as follows:
foo.py contains:
class Foo():
print("foo")
pkg/__init__.py contains:
from foo import Foo
script.py contains:
from pkg import Foo
foo = Foo()
From the directory where script.py is located, I can run python script.py and it results in "foo" being printed.
How is pkg/__init__.py able to successfully import Foo even though foo.py is located in a higher level directory?