[Python-ideas] strptime without second argument as an inverse to __str__
Skip Montanaro
skip at pobox.com
Mon Aug 4 22:14:11 CEST 2014
On Mon, Aug 4, 2014 at 2:23 PM, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
>
> On Mon, Aug 4, 2014 at 3:00 PM, Skip Montanaro <skip at pobox.com> wrote:
>>
>> > Why is this question relevant for Ram's proposal?
>>
>> It would seem to have some impact on how hard it is to create a
>> general inverse. Will one format work for all platforms ("one and
>> done"), or will the inverse implementation potentially have to be
>> updated as new platforms come into (or go out of) existence?
>
>
> I think str(datetime) format is an implementation detail to the same extent
> as str(int) or str(float) is. In the past, these variations did not prevent
> providing (sometimes imperfect) inverse.
I took a look at whatever version of CPython I have laying about (some
variant of 2.7). str(datetime) seems to be well-defined as calling
isoformat with " " as the separator. The only caveat is that if the
microsecond field is zero, it's omitted.
If that behavior holds true in 3.x, only two cases require consideration:
%Y-%m-%d %H:%M:%S
%Y-%m-%d %H:%M:%S.%f
Skip
More information about the Python-ideas
mailing list