[Python-ideas] strptime without second argument as an inverse to __str__
Steven D'Aprano
steve at pearwood.info
Tue Aug 5 03:39:44 CEST 2014
On Mon, Aug 04, 2014 at 10:56:56PM +0200, Wolfgang Maier wrote:
[...]
> it does hold true in 3.x, but the documented behavior is slightly more
> complex (I assume also in 2.x):
>
> datetime.__str__()
> For a datetime instance d, str(d) is equivalent to d.isoformat(' ').
Since str(d) is documented to use a well-defined format, then I agree
that it makes sense to make the second argument to d.strptime optional,
and default to that same format. The concern I had was the sort of
scenario Skip suggested: I might write out a datetime object as a string
on one machine, where the format is X, and read it back elsewhere, where
the format is Y, leading to at best an exception and at worse incorrect
data.
+1 on the suggestion.
--
Steven
More information about the Python-ideas
mailing list