Please, read throughout, the question. I'm not asking when and why to use import vs from import. Thanks.
I'm learning python and I really like it. I was able to manage and build some codes that help me with file storage and api calls, this sort of stuff.
However, due to the fact this is all "homemade" study, by searching the internet and so on, I wanted to start and understand more things related to the core mechanics of python itself.
As far as I know, I can use the import function in order to load a module or a submodule in my code, and this makes the module available to me for calling the methods associated to it (and if I'm wrong in any part, or the terminology is not correct, please let me know)
In that sense, I can use the from ModEx import submodule to import a module within this module (as far as I was able to understand). In this way, it makes it easier to build a code without using the module.submodule solution that can cause confusion and is a pain in the bottom to write it several times.
In that sense, I can also try to do something like import module.submodule, and this works in certain cases. But, just for learning purposes, I tried to apply the same concept while learning PyQt5, by doing something like this:
import PyQt5.QtWidgets.QApplication
However, this solution doesn't work. The console gives back the error
No module named 'PyQt5.QtWidgets.QApplication'; 'PyQt5.QtWidgets' is not a package
So, I tried using the help() function in Shell, so I could compare the differences between the
import PyQt5.QtWidgets
vs
import PyQt5.QtWidgets.QApplication
And I see that PyQt5.QtWidgets.QApplication starts like this:
PyQt5.QtWidgets.QApplication = class QApplication(PyQt5.QtGui.QGuiApplication)
Meanwhile PyQt5.QtWidgets:
Help on module PyQt5.QtWidgets in PyQt5: NAME PyQt5.QtWidgets
So, I clearly see that PyQt5.QtWidgets is a module, meanwhile PyQt5.QtWidgets.QApplication is a class.
Is that right? and if it is, why I can import the class by using the
from module import class,
but I can't
import module.class
?
Probably is not a very logic question, but I wanted somebody teaching me why is that. And again, if you see my terminology being a bit off, correct me so I can learn from it as well. I tried by digging it online, but I was unlucky.
Thank you!