[Python-ideas] strptime without second argument as an inverse to __str__
Alexander Belopolsky
alexander.belopolsky at gmail.com
Mon Aug 4 20:40:57 CEST 2014
On Mon, Aug 4, 2014 at 2:15 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> > What do you think about having `datetime.strptime`, when called without a
> > `format` for the second argument, be a precise inverse of
> > `datetime.__str__`? This is because I don't currently see an obvious way
> to
> > get an inverse of `datetime.__str__`, and this seems like an okay place
> to
> > put it.
>
> Is str(datetime) guaranteed to use a specific format, or is that an
> implementation detail?
Why is this question relevant for Ram's proposal? As long as str(datetime)
is guaranteed to be different for different datetimes, one should be able
to implement an inverse. The inverse function should accept ISO format
(with either ' ' or 'T' separator) and str(datetime) if it is different in
the implementation.
I agree that datetime type should provide a simple way to construct
instances from well-formatted strings, but I don't think
datetime.strptime() is a good choice of name. I would much rather have
date(str), time(str) and datetime(str) constructors.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140804/1968fb75/attachment.html>
More information about the Python-ideas
mailing list