D
D
ddshadoww2015-09-19 20:20:37
Python
ddshadoww, 2015-09-19 20:20:37

Trouble with importing modules in Python?

Hello, I've run into this problem. There is a directory package/__init__.py, package2.py where package is a folder. Outside this folder, there is also a package1.py file containing the following code:

import package.package2.summa

print(summa(1,2))

and this code is not executed. Can you tell me what is the problem here? Works if I enter like this:
from package.package2 import summa
Thank you.
PS Python 3.5 and here is the screenshot with the error
795bb686993645db910b154b5ba06c6e.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Meehalkoff, 2015-09-19
@ddshadoww

There is no problem here. You should study the module import mechanism in more detail.

V
Vitaly, 2015-09-19
@denshi

But the answer is already in the question. Use:
This notation:
doesn't work because it imports a function, and the import command imports a module (or package).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question