Reputation: 166
I'm trying to import a simple package, but it doesn't work.
I have a "package" directory that contains two files:
foo.py
(with a function called fct)__init__.py
(with nothing in it)Here is the content of tests.py
:
import package.foo
foo.fct(7)
But it doesn't work.
If I change the import line to from package.foo import fct
, I can execute the function.
Upvotes: 0
Views: 65
Reputation: 310167
You need import package.foo as foo
or one of the alternatives below ...
import package.foo
package.foo.fct(7)
or:
import package.foo as foo
foo.fct(7)
or possibly:
from package import foo
foo.fct(7)
Upvotes: 4