Can anyone explain which ‘import’ is universal, so I don’t need to write for example:
from numpy import *
import numpy
import numpy as np
from numpy.linalg import *
Why not import numpy or from numpy import * to incude all from “numpy”?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not sure what you mean by “all from numpy”, but you should never need to use more than one form of
importat a time. They do different things:Option One:
importimport numpywill bring the entire numpy module into the current namespace. You can then reference anything from that moudule asnumpy.dotornumpy.linalg.eig.Option Two:
from ... import *from numpy import *will bring all of the public objects from numpy into the current namespace as local references. If the package contains a list named__all__then this command will alsoimportevery sub-module defined in that list.For numpy this list includes ‘linalg’, ‘fft’, ‘random’, ‘ctypeslib’, ‘ma’, and ‘doc’ last I checked. So, once you’ve run this command, you can call
dotorlinalg.eigwithout the numpy prefix.If you’re looking for an import that will pull every symbol from every submodule in the package into your namespace, then I don’t think there is one. You would have to do something like this:
which is, I think, what you’re trying to avoid.