[Python-ideas] Making datetime __str__ and isoformat more consistent

Ethan Furman ethan at stoneleaf.us
Fri Nov 1 22:29:16 CET 2013


On 11/01/2013 01:37 PM, MRAB wrote:
> On 01/11/2013 19:49, Ethan Furman wrote:
>> On 11/01/2013 11:15 AM, Skip Montanaro wrote:
>>>
>>> http://bugs.python.org/issue19475
>>>
>>> Do others agree with me that consistency in this situation is better than
>>> the current behavior?
>>
>> I haven't seen the arguments in favor of this awkward behavior, so I may change my mind, but at the moment I would
>> certainly argue for consistency: either emit microseconds in __str__ or ignore remaining microseconds or ignore a
>> trailing %f (or all three ;) .
>>
> Suppose there were, say, 900000 microseconds, i.e. 0.9 seconds?
>
> If the microseconds aren't shown by __str__, should it truncate or
> round?

My first (and preferred) option was to emit the microseconds (even if 0).

At the heart of this issue is: If datetime.datetime is not going to always emit the microseconds, then there should be 
an easy roundtrip method to get the value back; currently there is not.

Maybe the best fix is to make the csv module smarter about how it outputs datetime's (so it would always emit microseconds).

--
~Ethan~


More information about the Python-ideas mailing list