I’ve started working on Python for about a month now and I’ve ran into something I would like to understand better. It’s related to imports. So I have a module:
root.core.connectivity
Now in this module I have defined a class Connectivity. This module also has a __main__ only for testing purposes(not sure if this makes any differences).
Now if I do:
from root.core.connectivity import Connectivity as class_name
This works fine, however if I try:
import root.core.connectivity.Connectivity as class_name
This will fail with:
ImportError: No module named Connectivity
So my question is, why does it fail and what are the differences between the two statements.
Regards,
Bogdan
importtakes a module.from X import Ytakes a module in X, and any element of that module in Y.Connectivityis not a module.