I understand from Chris Yeh's helpful guide that the dot implies "in this directory" relative to the specific module that I'm running. But given this project:
project/
--main.py
--lib/
--bar.py
--foo.py
bar.py
:
class Ball:
pass
foo.py
:
from .bar import Ball
class SoccerBall(Ball):
pass
main.py
:
from lib.foo import SoccerBall
s = SoccerBall()
Running main.py
works as expected.
However, if I want to run foo.py
, I need to remove the dot from the import statement (something my IDE marks as an error):
from bar import Ball
I would expect the dot to be needed when I run foo.py
, and for main.py
to require the import as from .lib.bar import Ball
. What am I missing?
print(sys.version)
> 3.7.4 (default, Aug 13 2019, 15:17:50)