[Python-Dev] redux: fractional seconds in strptime

Skip Montanaro skip at pobox.com
Fri Jan 14 10:36:21 CET 2005


    Brett> The problem I have always had with this proposal is that the
    Brett> value is worthless, time tuples do not have a slot for fractional
    Brett> seconds.  Yes, it could possibly be changed to return a float for
    Brett> seconds, but that could possibly break things.

Actually, time.strptime() returns a struct_time object.  Would it be
possible to extend %S to parse floats then add a microseconds (or whatever)
field to struct_time objects that is available by attribute only?  In Py3k
it could worm its way into the tuple representation somehow (either as a new
field or by returning seconds as a float).

    Brett> My vote is that if something is added it be like %N but without
    Brett> the optional optional digit count.  This allows any separator to
    Brett> be used while still consuming the digits.  It also doesn't
    Brett> suddenly add optional args which are not supported for any other
    Brett> directive.

I realize the %4N notation is distasteful, but without it I think you will
have trouble parsing something like

    13:02:00.704

What would be the format string?  %H:%M:%S.%N would be incorrect.  It
works if you allow the digit notation: %H:%M:%S.%3N

I think that except for the logging module presentation of fractions of a
second would almost always use the locale-specific decimal point, so if
that problem is fixed, extending %S to understand floating point seconds
would be reasonable.

Skip



More information about the Python-Dev mailing list