Boris
Boris

Reputation: 166

Import a module from a package

I'm trying to import a simple package, but it doesn't work.

I have a "package" directory that contains two files:

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

Answers (1)

mgilson
mgilson

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

Related Questions