Replaced time module with my own on accident - help

S

Sean Berry

I was writing a little script to test different functions of the time
module. Like an idiot, I named the test script time.py.

Then when I tried to do a "import time" call, I got an error.

So, my time.py has overwritten the time.py builtin mod.

I have python 2.3 installed on a few different servers, so I was going to
copy over the .py file in /usr/local/lib/python2.3, but I could not find
one... not even on the servers where I didn't screw this up.

$ find . -name "time*"
../python2.3/timeit.py
../python2.3/timeit.pyc
../python2.3/timeit.pyo
../python2.3/lib-dynload/time.so

Where is the original time.py kept? And is there an easier way to get it
back?

Thanks and sorry about my ignorance.
 
C

Carlos Ribeiro

I was writing a little script to test different functions of the time
module. Like an idiot, I named the test script time.py.

Then when I tried to do a "import time" call, I got an error.

So, my time.py has overwritten the time.py builtin mod.

Your problem may be a little bit simpler to solve. When you do a
'import time' is looks first in the current directory; if it doesn't
find a module by that name, it searches the module path (I forgot the
name), which usually on Unix points to the lib subdirectory of your
Python installation. It appears that you own (broken) time.py module
is just getting the precedence over the standard one. If that's the
case, just removing your own time.py (or renaming it) should solve
your problem.

--
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: (e-mail address removed)
mail: (e-mail address removed)
 
S

Sean Berry

I was writing a little script to test different functions of the time
module. Like an idiot, I named the test script time.py.

Then when I tried to do a "import time" call, I got an error.

So, my time.py has overwritten the time.py builtin mod.

Your problem may be a little bit simpler to solve. When you do a
'import time' is looks first in the current directory; if it doesn't
find a module by that name, it searches the module path (I forgot the
name), which usually on Unix points to the lib subdirectory of your
Python installation. It appears that you own (broken) time.py module
is just getting the precedence over the standard one. If that's the
case, just removing your own time.py (or renaming it) should solve
your problem.
[/QUOTE]

Thanks for the heads up. I had already tried that, but I did not realize
that the .pyc file had been compiled and was in the directory as well.
Deleted it and all is fine.

Thanks Carlos.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top