Just to elaborate on what other people have said, numpy is an especially bad module to use import *
with.
pylab
is meant for interactive use, and it's fine there. No one wants to type pylab.zeros
over and over in a shell when they could just type zeros
. However, as soon as you start writing code, everything changes. You're typing it once and it's staying around potentially forever, and other people (e.g. yourself a year down the road) are probably going to be trying to figure out what the heck you were doing.
In addition to what @unutbu already said about overriding python's builtin sum
, float
int
, etc, and to what everyone has said about not knowing where a function came from, numpy
and pylab
are very large namespaces.
numpy
has 566 functions, variables, classes, etc within its namespace. That's a lot! pylab
has 930! (And with pylab, these come from quite a few different modules.)
Sure, it's easy enough to guess where zeros
or ones
or array
is from, but what about source
or DataSource
or lib.utils
? (all of these will be in your local namespace if you do from numpy import *
If you have a even slightly larger project, there's a good chance you're going to have a local variable or a variable in another file that's named similar to something in a big module like numpy
. Suddenly, you start to care a lot more about exactly what it is that you're calling!
As another example, how would you distinguish between pylab
's fft
function and numpy
's fft
module?
Depending on whether you do
from numpy import *
from pylab import *
or:
from pylab import *
from numpy import *
fft
is a completely different thing with completely different behavior! (i.e. trying to call fft
in the second case will raise an error.)
All in all, you should always avoid from module import *
, but it's an especially bad idea in the case of numpy
, scipy
, et. al. because they're such large namespaces.
Of course all that having been said, if you're just futzing around in a shell trying to quickly get a plot of some data before move on to actually doing something with it, then sure, use pylab
. That's what it's there for. Just don't write something that way that anyone might try to read later on down the road!
</rant>