467,074 Members | 1,070 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,074 developers. It's quick & easy.

Weird AttributeError With Imports

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!
Oct 28 '07 #1
  • viewed: 2515
Share:
3 Replies
Juha S. wrote:
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
Oct 28 '07 #2
Peter Otten wrote:
Juha S. wrote:

>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
Yes, I did have mytime.py named as time.py previously. Now that I
deleted the .pyc it seems to work fine. Thanks!
Oct 28 '07 #3
En Sun, 28 Oct 2007 14:50:24 -0300, Juha S. <ju*****@gmail.comescribi�:
Peter Otten 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?

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!

--
Gabriel Genellina

Oct 29 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Gonçalo Rodrigues | last post: by
reply views Thread by Erlend Fuglum | last post: by
1 post views Thread by George Sakkis | last post: by
14 posts views Thread by Nak | last post: by
16 posts views Thread by iwdu15 | last post: by
5 posts views Thread by robinsiebler@gmail.com | last post: by
3 posts views Thread by ssecorp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.