[Python-Dev] datetime.date.today() raises "AttributeError: time"

Tal Einat taleinat at gmail.com
Sun Nov 16 14:00:58 CET 2008


For an unknown reason, datetime.date.today() began throwing a cryptic
"AttributeError: time" exception. It took me a while to figure out
that this was caused by an accidental overriding of the built-in
'time' module.

Here's an example interactive session which shows the problem:

[tal ~]$ touch time.py
[tal ~]$ python
Python 2.5.2 (r252:60911, Jul 17 2008, 10:47:50)
[GCC 4.0.1 (Apple Inc. build 5484)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.__file__
'time.py'
>>> import datetime
>>> datetime.date.today()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: time
>>>

Here I used version 2.5.2, but I checked and this also happens on 2.6.


It this desired behavior?

At the very least the exception should be more detailed, perhaps to
the point of suggesting the probable cause of the error (i.e.
overriding the time module).

- Tal


More information about the Python-Dev mailing list