[Python-Dev] redux: fractional seconds in strptime
Skip Montanaro
skip at pobox.com
Fri Jan 14 19:26:02 CET 2005
>> 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.
Brett> Why is that incorrect?
Because "704" represents the number of milliseconds, not the number of
nanoseconds.
I'm sure that in some applications people are interested in extremely short
time scales. Writing out hours, minutes and seconds when all you are
concerned with are small fractions of seconds (think high energy physics)
would be a waste. In those situations log entries like
704 saw proton
705 proton hit neutron
706 saw electron headed toward Saturn
might make perfect sense. Parsing the time field entirely within
time.strptime would be at least clumsy if you couldn't tell it the scale of
the numbers you're dealing with. Parsing with %N, %3N or %6N would give
different values (nanoseconds, milliseconds or microseconds).
Skip
More information about the Python-Dev
mailing list