time, calendar, datetime, etc

Skip Montanaro skip at pobox.com
Thu Jul 31 13:22:03 EDT 2003


    Ben> Problem is, time.localtime() doesn't return a 9-element tuple any
    Ben> more, it returns a struct_time. (Since 2.2, I think.)

Struct_time objects work like tuples, and you get the added
benefit of named attribute access:

    >>> t = time.localtime()
    >>> t
    (2003, 7, 31, 12, 19, 35, 3, 212, 1)
    >>> t[2]
    31
    >>> t.tm_mday
    31
    >>> t.tm_isdst
    1
    >>> t[-1]
    1
    >>> t[0:3]
    (2003, 7, 31)

Skip





More information about the Python-list mailing list