Time module is not behaving.

Gary Herron gherron at islandtraining.com
Tue Mar 25 11:49:55 EDT 2008


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.




More information about the Python-list mailing list