I have a folder called myPackage
which contains
- a file called
myModule.py
- an empty file called
__init__.py
The file myModule.py
is as follows:
def foo():
print("Hello!")
Now each of the following files would run smoothly and do what I expect:
First option:
import myPackage.myModule
myPackage.myModule.foo()
Second option:
from myPackage import myModule
myModule.foo()
Third option:
from myPackage.myModule import foo
foo()
My question is what happens if I run a script containing:
import myPackage
The import alone does make the interpreter complain... but then I would have expected the following to work:
myPackage.myModule1.foo()
which is not the case.
Can I do import myPackage
? I guess so, since otherwise I would have gotten an error straight away...
What am I supposed to do next?