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

Ethan Furman ethan at stoneleaf.us
Sat Nov 2 20:43:51 CET 2013


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).

--
~Ethan~


More information about the Python-ideas mailing list