Syntax Problem with strptime in Python 2.4

skip at pobox.com skip at pobox.com
Mon Sep 8 06:51:48 EDT 2008


    >> Apparently, use of strptime of datetime needs a workaround in Python
    >> 2.4 to work properly. The workaround is d =
    >> datetime.datetime(*(time.strptime(date_string,
    >> format)[0:5])). However, when I try to use it, or even use it the
    >> regular way, it fails with AttributeError: type object
    >> 'datetime.datetime' has no attribute 'datetime'.

Works for me:

    >>> import datetime
    >>> format = '%Y%m%d_%H%M%S'
    >>> import time
    >>> print time.strptime('20080321_113405', format)[0:5]
    (2008, 3, 21, 11, 34)
    >>> d = datetime.datetime(*time.strptime('20080321_113405', format)[0:5])
    >>> d
    datetime.datetime(2008, 3, 21, 11, 34)

Python 2.4.4, Mac OS X 10.5.4.

Skip



More information about the Python-list mailing list