Order in which modules are imported
Tim Chase
python.list at tim.thechases.com
Fri Feb 22 18:48:20 EST 2008
>>>> import random
>>>> from pylab import *
>>>> x = random.uniform(0,1)
>
> Traceback (most recent call last):
I suspect that
>>> 'random' in dir(pylab)
returns True...this would be one of those reasons that "from
<module> import *" is scowled upon. You have to know what
<module> is dumping into your namespace, or otherwise, it will
likely tromp atop other things you have defined before.
Looking at the source of pylab.py, I see
from numpy.random import *
and numpy.random has a "random" function in it. This waltzes
atop your random module. A modern fandango-on-core...perhaps
"fandango on namespace".
The other alternative, if you must do "from pylab import *",
would be to import the system "random" module under another name:
import random as pyrandom
from pylab import *
...
x = pyrandom.uniform(0,1)
-tkc
More information about the Python-list
mailing list