so this is a collection of questions that are more to clarify things and help better understand rather than an issue I am having.
I apologise now if I got things wrong or if these questions have been answered before. I wasn't able to find them.
First clarification I want to ask is:
Let us assume:
import scipy
First, I have noticed that you cannot in general access a module in a package by doing import package and then trying to access package.module.
For example scipy.io
You often have to do import package.module
or even import astropy.io.fits
, or you can do from package import module
.
My question is why is this the case, and why is it so random -dependent on the package? I can't seem to identify any stable pattern. Is it due to the fact that some of these libraries (packages) are very big and in order to not have memory problems it only imports the core attributes/modules?
The second question:
It relates to actually checking the size of these packages. Is there any way to see how big they are when imported? Any way of knowing what will work and what won't other than trying it? I guess I could check with sys.modules
and try to obtain it from there?
The third and final question:
In the scenario that I am not running my code on a Raspberry Pi and I don't necessarily have to worry about the memory issue (if that is the reason why they don't allow direct access), is there any way of actually importing package, such that it also loads all the sub packages?
I am just being lazy and wondering if it is possible. I am aware that it isn't good practice, but curiosity killed the cat.
Just to update and make it accessible to people to see related questions I have looked at:
This answer gives good advice on good general practice: What are good rules of thumb for Python imports?
Why can't I use the scipy.io? just like the documentation explains why the subpackage isn't necessarily imported
Then there is obviously the documentation:
https://docs.python.org/3/reference/import.html#packages
Section 5.2.1 is the reason why import scipy
doesn't also import scipy.io
, but I was wondering why would developers not make it an automated process.
This question is actually similar to part of my question but doesn`t seem to have a clear answer Python complex subpackage importing
Status of Questions:
Question 1: Good reason in answers
Question 2: Pending
Question 3: Pending