Order in which modules are imported

Roy Smith roy at panix.com
Sat Feb 23 00:46:12 CET 2008


In article 
<8f6dc46e-2f15-4d7a-961b-15cad7255a38 at 64g2000hsw.googlegroups.com>,
 tkpmep at hotmail.com wrote:

> I imported two modules (random and matplotlib), and found that the
> functions available to me from the random module depended on the order
> in which the imports occured. In particular, if I import random first,
> none of its functions seem to be available, while if I import it after
> matplotlib, I seem to have access to all of its functions. What could
> the problem be?
> 
> Thomas Philips
> 
> 
> >>> import random
> >>> from pylab import *
> >>> x = random.uniform(0,1)
> 
> Traceback (most recent call last):
>   File "<pyshell#2>", line 1, in <module>
>     x = random.uniform(0,1)
> AttributeError: 'builtin_function_or_method' object has no attribute
> 'uniform'
> >>> help(random)
> Help on built-in function random_sample:

I'm guessing the module pylab has a symbol in it named "random", which is 
over-writing the name "random" you created with the first import.

Try changing it to:

import random
import pylab

and then referring to the things in pylab by their qualified 
(pylab.whatever) names.



More information about the Python-list mailing list