By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

Weird AttributeError With Imports

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.