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

MRAB python at mrabarnett.plus.com
Sat Nov 2 22:19:04 CET 2013


On 02/11/2013 19:43, Ethan Furman wrote:
> On 11/02/2013 02:25 AM, Nick Coghlan wrote:
>> On 2 November 2013 12:49, MRAB <python at mrabarnett.plus.com> wrote:
>>> On 02/11/2013 02:17, Alexander Belopolsky wrote: +1
>>>
>>> Guaranteeing round-trip does seem like a reasonable behaviour to
>>> me.
>>
>> It's been a while since I had to deal seriously with date parsing,
>> but at the time, emitting microseconds was a fairly surefire way to
>> break most utilities that nominally supported date parsing.
>> Roundtripping is good, but interoperability is important too, and
>> as far as I am aware, microsecond support when parsing is still
>> sketchy with many date parsing tools.
>>
>> Ensuring that emitting and consuming microseconds is easy would
>> definitely be a good thing, but unless general date parsing
>> support (not just in Python, but in programming utilities in
>> general) has improved more dramatically in recent years than I
>> believe it has, emitting microseconds by default would be a
>> backwards compatibility breach.
>
> The thread seems to be leaning towards leaving the current __str__
> behavior as-is, and simply adding enough smarts to __new__ to be able
> to reconvert back to a date/datetime instance (whether or not
> microseconds have been emitted).
>
The OP was using strptime, so perhaps the simplest solution would be to
allow its 'format' argument to default to None, which would mean ISO
format with optional microseconds.


More information about the Python-ideas mailing list