⏵ ls
module.py script.py
⏵ cat module.py
def foo2():
print('foo2 called.')
⏵ cat script.py
import module
def foo1():
print('foo1 called.')
foo1()
module.foo2()
⏵ python3 script.py
foo1 called.
foo2 called.
Import by name: ⏵ cat script.py
from module import foo2
def foo1():
print('foo1 called.')
foo1()
foo2()
⏵ python3 script.py
foo1 called.
foo2 called.I was using Python 2 at the time. Python 3 was still relatively new. Not sure how much difference it makes for your example, but the import systems are different between 2 and 3.
"ImportError: attempted relative import with no known parent package"
Looks like I'm back to having to learn a bunch of stuff about scripts and modules again?
I'm sure if I'd taken the time to try and fix it I eventually could have and at this point i've had more experience with a bunch of different languages, so I'm sure it's not as bad as I remember.
I imagine it's one of those cases where if i were to go back and laugh about how stupid I was, but ya know, those first impressions.
If you know how a path and relative path work from the shell, there is only one thing: touch __init__.py.
These are on the import doc page and beginners tutorial.