Whither datetime.date ?

Discussion in 'Python' started by Harald Hanche-Olsen, Feb 26, 2005.

  1. I'm confused. I was going to try linkchecker, and it dies with a
    traceback ending in

    File "/usr/local/lib/python2.4/calendar.py", line 32, in _localized_month
    _months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
    AttributeError: 'module' object has no attribute 'date'

    Sure enough, there is no datetime.date, but there is a datetime.Date:

    Python 2.4 (#2, Feb 19 2005, 20:35:23)
    [GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import datetime
    >>> dir(datetime)

    ['Date', 'DateTime', ...]

    However, the Library Reference clearly states that datetime.date
    should exist. Granted, it's been a while since I used python in
    anger, but isn't this what it says?

    http://www.python.org/doc/2.4/lib/node243.html
    http://www.python.org/doc/2.4/lib/datetime-date.html

    Moreover, the datetime.date class is supposed to have a strftime()
    method. datetime.Date does not.

    I'm beginning to wonder if the FreeBSD python package is at fault.

    Or what is really going on here?

    --
    * Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
    - Debating gives most of us much more psychological satisfaction
    than thinking does: but it deprives us of whatever chance there is
    of getting closer to the truth. -- C.P. Snow
     
    Harald Hanche-Olsen, Feb 26, 2005
    #1
    1. Advertising

  2. Harald Hanche-Olsen wrote:
    > I'm beginning to wonder if the FreeBSD python package is at fault.


    Maybe - at my system, it has no Date or DateTime

    Python 2.4.1a0 (#2, Feb 9 2005, 12:50:04)
    [GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import datetime
    >>> dir(datetime)

    ['MAXYEAR', 'MINYEAR', '__doc__', '__file__', '__name__', 'date',
    'datetime', 'datetime_CAPI', 'time', 'timedelta', 'tzinfo']
    >>>



    Maybe this is a clash between a custom datetime module and the python one?

    What does

    python2.4 -v -c "import datetime"

    give you?
    --
    Regards,

    Diez B. Roggisch
     
    Diez B. Roggisch, Feb 26, 2005
    #2
    1. Advertising

  3. Harald Hanche-Olsen

    Tim Peters Guest

    [Harald Hanche-Olsen]
    > I'm confused. I was going to try linkchecker, and it dies with a
    > traceback ending in
    >
    > File "/usr/local/lib/python2.4/calendar.py", line 32, in _localized_month
    > _months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
    > AttributeError: 'module' object has no attribute 'date'
    >
    > Sure enough, there is no datetime.date, but there is a datetime.Date:
    >
    > Python 2.4 (#2, Feb 19 2005, 20:35:23)
    > [GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
    > Type "help", "copyright", "credits" or "license" for more information.
    > >>> import datetime
    > >>> dir(datetime)

    > ['Date', 'DateTime', ...]
    >
    > However, the Library Reference clearly states that datetime.date
    > should exist. Granted, it's been a while since I used python in
    > anger, but isn't this what it says?
    >
    > http://www.python.org/doc/2.4/lib/node243.html
    > http://www.python.org/doc/2.4/lib/datetime-date.html
    >
    > Moreover, the datetime.date class is supposed to have a strftime()
    > method. datetime.Date does not.
    >
    > I'm beginning to wonder if the FreeBSD python package is at fault.
    >
    > Or what is really going on here?


    As you've deduced, you're certainly not getting Python's builtin
    datetime module. Therefore you must be getting some other datetime
    module. Run Python with the "-v" switch to get output telling you how
    imports are resolved. That will show you where this other datetime
    module is coming from. Remember that Python searches along sys.path
    to resolve imports, taking the first thing it finds with the right
    name. You almost certainly have something _called_ datetime earlier
    in your PYTHONPATH than where the standard Python libraries appear.
     
    Tim Peters, Feb 26, 2005
    #3
  4. + Tim Peters <>:

    | As you've deduced, you're certainly not getting Python's builtin
    | datetime module.

    Argh. Yeah, I've had one lying around in my personal python directory
    since 2000, had totally forgotten it was there. This one ...

    *** Author: Jeff Kunce <>
    *** Download from: http://starship.skyport.net/crew/jjkunce

    Removed it, now all is well.

    Thanks for pointing out the blindingly obvious.

    --
    * Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
    - Debating gives most of us much more psychological satisfaction
    than thinking does: but it deprives us of whatever chance there is
    of getting closer to the truth. -- C.P. Snow
     
    Harald Hanche-Olsen, Feb 26, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    732
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    555
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    403
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    350
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    774
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page