Time module is not behaving.

Jeff Lofaro jjlofaro at yahoo.com.au
Wed Mar 26 10:47:11 CET 2008


Yep that does it.

Thanks Gary.

----- Original Message ----
From: Gary Herron <gherron at islandtraining.com>
To: jjlofaro <jjlofaro at yahoo.com.au>
Cc: python-list at python.org
Sent: Wednesday, 26 March, 2008 2:49:55 AM
Subject: Re: Time module is not behaving.

jjlofaro wrote:
> Hi
>
> I'm just getting myself going again on Python and would appreciate any 
> help.
>
> My install of Python seems to have some difficulty loading and using 
> the time module in a script.  Strange thing is that if I start another 
> instance of Python I can type in my program manually/interactively and 
> it works.
>
> The version of Python I am using is...
> *
> Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2*
>
> Installed on a Ubuntu 7.10 workstation.
>
> Here's my little program....
>
> *jeff at office:~/tmp$ more < time.py
>
> import time
> *
Right there is the problem. Your program, named time.py, is hiding the 
Python supplied module.  So that import of time is finding and 
re-importing itself.  Rename your script to something that won't shadow 
a Python library module.

Gary Herron

> *print time.time()*
>
> And this is what happens when I run it....
>
> *jeff at office:~/tmp$ python time.py
>
> Traceback (most recent call last):
>   File "time.py", line 1, in <module>
>     import time
>   File "/home/jeff/tmp/time.py", line 2, in <module>
>     print time.time()
> TypeError: 'module' object is not callable
> Error in sys.excepthook:
> Traceback (most recent call last):
>   File "/var/lib/python-support/python2.5/apport_python_hook.py", line 
> 38, in apport_excepthook
>     from apport.fileutils import likely_packaged
>   File "/var/lib/python-support/python2.5/apport/__init__.py", line 1, 
> in <module>
>     from apport.report import Report
>   File "/var/lib/python-support/python2.5/apport/report.py", line 14, 
> in <module>
>     import subprocess, tempfile, os.path, urllib, re, pwd, grp, os, sys
>   File "/usr/lib/python2.5/urllib.py", line 28, in <module>
>     import time
>   File "/home/jeff/tmp/time.py", line 2, in <module>
>     print time.time()
> TypeError: 'module' object is not callable
>
> Original exception was:
> Traceback (most recent call last):
>   File "time.py", line 1, in <module>
>     import time
>   File "/home/jeff/tmp/time.py", line 2, in <module>
>     print time.time()
> TypeError: 'module' object is not callable
>
> jeff at office:~/tmp$ *
>
> Any hints or tips appreciated.
> Jeff.







      Get the name you always wanted with the new y7mail email address.
www.yahoo7.com.au/y7mail

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080326/4ed0c814/attachment.html>


More information about the Python-list mailing list