473,287 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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
3 2781
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gonçalo Rodrigues | last post by:
Hi, I use the unittest module for testing a given module's functionality, by lumping several test classes and then at the end a simple if __name__ == "__main__": unittest.main() In one of...
2
by: dont bother | last post by:
Hey, I am trying to run the following example from diveintopython import urllib sock = urllib.urlopen("http://diveintopython.org/") htmlSource = sock.read() sock.close() print htmlSource
0
by: Erlend Fuglum | last post by:
I have tried and tried, but cannot figure out the source of the following error: AttributeError: 'module' object has no attribute 'menyHMTL' __doc__ = 'Attribute not found.' __getitem__ =...
1
by: George Sakkis | last post by:
I came across a strange error when trying to define a settable property for a new-style subclass of UserArray (Numeric). Here's a shorter example that reproduces the problem: from UserArray...
14
by: Nak | last post by:
Hi there, It's probably me being weird more than the function but I'm having problems with it doing as it should. I have a C++ application with 2 resources of custom types, RT_INIFILE @...
16
by: iwdu15 | last post by:
hi, i have a few forms in my project. when i load form1 (startup for) all is fine, then i open another one and use a login screen to call yet another and all is still fine, but then when i try to...
0
by: kepioo | last post by:
I am running a script (summary.py) which is calling the method logException in another module ( pytool). Yesterday, ard 18:50, all of a sudden summary.py was throwing the exception : ...
5
by: robinsiebler | last post by:
I have a data structure that looks like this: # dates = {'2007': {'25': {'06/23/07': {'aerosmith': , # 'Metallica': }, # 'last_song': }}}...
3
by: ssecorp | last post by:
I was looking into currying and Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) on win32 Type "copyright", "credits" or "license()" for more information. ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.