From: Robert K. <rob...@gm...> - 2006-03-18 18:11:36
|
ahmet nurlu wrote: > Hi, > I wrote a random walk program which you will find below. When I run it > from the terminal, it gives error which I am not able to figure out what > could be wrong. From the bash shell, I give a command > >python2.4 random.py > It gives error: > ----------------------------------------------------------------------------------------- > Traceback (most recent call last): > File "random.py", line 2, in ? > from pylab import * > File "/usr/lib/python2.4/site-packages/pylab.py", line 1, in ? > from matplotlib.pylab import * > File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line 196, > in ? > import mlab #so I can override hist, psd, etc... > File "/usr/lib/python2.4/site-packages/matplotlib/mlab.py", line 58, in ? > import sys, random > File "/home/ofenerci/workspace/random.py", line 11, in ? > if (rand() > 0.5): > NameError: name 'rand' is not defined > [3] Done gedit random.py > ------------------------------------------------------------------------------------------------------------- > When I write the program step by step inside the python shell or run it > inside the python-idle, everything goes smoothly and it doesn't give any > error. I don't know why gives error, If I run it from the terminal. Python always searches the current directory for modules first. You have named your file random.py which is the same as the standard library module random.py. matplotlib.mlab is trying to import the standard library module, but is getting your instead. Rename your file to something other than random.py. -- Robert Kern rob...@gm... "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |