I am trying to understand relative imports in python (python3), and the following simple piece of code does not work. I would like to know what's missing in my understanding of relative imports.
I have a directory structure like this:
example/
a.py
b.py
a.py has the following code:
def test_print():
print("test")
and b.py has the following code:
from . import a
a.test_print()
When I run b.py, I get an ImportError: cannot import name 'a'
. However, if I go one level above (cd ..
), and run python -m example.b
, it runs without any errors.