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
import takes a module. from X import Y takes a module in X, and any element of that module in Y. Connectivity is not a module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With