How did I screw this up?
Christopher T King
squirrel at WPI.EDU
Fri Jul 23 12:25:18 EDT 2004
On Fri, 23 Jul 2004, Widgeteye wrote:
> I deleted the file and rebooted (silly I know) but nothing seems to help.
> What do I do now and what happened?????
Initially what happened is that the 'import random' chose your script
(random.py) to import, rather than the builtin one. This is normal Python
behaviour, and for that reason you shouldn't give your script the same
name as a builtin library you want to use.
The reason why this kept happening, even after you deleted random.py, is
(I believe) because there is still a random.pyc in your /shared/src
directory. This is a compiled version of random.py that is built whenever
Python imports a module, and the .py file is newer than the .pyc file. In
your case, what I think is happening is that Python is loading the
local .pyc file (which contains your code), hitting the error, and then
printing a traceback using the only random.py it can find, i.e. the
builtin one (which makes it seem like it was overwritten). The .pyc is
not being rebuilt because it is newer than what Python thinks is the
corresponding .py file (and always will be). The solution in this case is
simply to delete the /shared/src/random.pyc file.
If that's not the case, and /usr/local/lib/python23/random.py really is
corrupted (open it and see if it contains your code first), you can
download random.py from (sorry for the long URL)
and use it to replace the broken random.py. *Don't* do this unless you
confirm that the .pyc file is not the culprit.
Hope this helps.
More information about the Python-list