Order in which modules are imported

tkpmep at hotmail.com tkpmep at hotmail.com
Fri Feb 22 18:21:31 EST 2008


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:

random_sample(...)
    Return random floats in the half-open interval [0.0, 1.0).

    random_sample(size=None) -> random values


In sharp contrast, I get what I expect when I reverse the order of the
imports.
>>> from pylab import *
>>> import random
>>> random.uniform(0,1)
0.75262941795069283
>>> help(random)
Help on module random:

NAME
    random - Random variable generators.

FILE
    c:\python25\lib\random.py
.
.
.







More information about the Python-list mailing list