by markmark · 5y ago · 0 comments
⏵ 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."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 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.