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

Ethan Furman ethan at stoneleaf.us
Sat Nov 2 23:01:38 CET 2013


On 11/02/2013 02:19 PM, MRAB wrote:
> On 02/11/2013 19:43, Ethan Furman wrote:
>> On 11/02/2013 02:25 AM, Nick Coghlan wrote:
>>>
>>> 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.

+1 with the caveat that None would mean whatever __str__ outputs (which at this time is coincidentally an ISO format).

--
~Ethan~


More information about the Python-ideas mailing list