Weird AttributeError With Imports

J

Juha S.

I'm getting a "AttributeError: 'module' object has no attribute 'clock'"
when importing a module from within two packages related to the line:
"self.lastTime = time.clock()" in the __init__() of the class Time in
the target module.

The module (mytime.py) sits in a package hierarchy such as the following
"packageA.packageB.mytime", and imports the Python module "time" like
this: "import time"

In another module outside of both packages (in a folder that holds the
other package folders) I do this:


from packageA.packageB import mytime

timer = mytime.Time() #Throws the above AttributeError


Strangely it seems that if I create a Time object in mytime.py
everything works perfectly. I have no idea why I'm getting this error,
so any help is welcome!
 
P

Peter Otten

Juha said:
I'm getting a "AttributeError: 'module' object has no attribute 'clock'"
when importing a module from within two packages related to the line:
"self.lastTime = time.clock()" in the __init__() of the class Time in
the target module.

You probably have a time module that you wrote yourself and which is now
hiding the one in python's standard library. Was your mytime.py formerly
named time.py, and if so, did you remove the corresponding time.pyc?

Peter
 
J

Juha S.

Peter said:
Juha S. wrote:



You probably have a time module that you wrote yourself and which is now
hiding the one in python's standard library. Was your mytime.py formerly
named time.py, and if so, did you remove the corresponding time.pyc?

Peter

Yes, I did have mytime.py named as time.py previously. Now that I
deleted the .pyc it seems to work fine. Thanks!
 
G

Gabriel Genellina

Yes, I did have mytime.py named as time.py previously. Now that I
deleted the .pyc it seems to work fine. Thanks!

Wow! Most standard crystall balls would tell just about the time.py
problem. Yours is certainly a very sophisticated one! It was even capable
of detecting a rename and a forgotten .pyc file - that's far beyond the
usual range! Congratulations!
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top