Is there any difference, subtle or not so subtle, between the effects of the following import statements? I have found both used in example programs and sure enough, they both seem to work. It would go against the grain of Python’s “there is only one way to do stuff” if they were totally equivalent in function, so I’m puzzled. I’m just starting out in Python and trying to keep good habits. So for instance, for the interpolate module in the scipy package …
from scipy import interpolate as spi
or
import scipy.interpolate as spi
both appear to put the interpolate module in the current namespace as spi
It’s a matter of taste, really.
In this particular case, I would use
import scipy.interpolate as spi, to remember thatinterpolateis a submodule ofscipy. If I were to import a function from a module, I would usefrom module import function.The only thing is, be consistent with the convention you choose.