[Python-ideas] strptime without second argument as an inverse to __str__
Andrew Barnert
abarnert at yahoo.com
Thu Aug 7 04:24:33 CEST 2014
On Aug 6, 2014, at 17:19, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:
>
> On Wed, Aug 6, 2014 at 7:55 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
>> Given that, unlike all the obvious parallel cases (int, float, etc.) this constructor will not accept the repr, I'm not sure the answer comes out the same.
>
> The parallel is in accepting str, not repr.
Is it? Sure, I'll accept that's the parallel you have in mind, but is it a good one?
The only way I can think to distinguish is this: For bytes, str, tuple, etc., there is no constructor from either string representation. For int, the two representations are identical. For float, they're different--and it's float(repr(f)) that gives you back the same value you started with. (Of course in the other direction, neither one is guaranteed to do so.) Also note that int can accept hex, etc. Python literal values as strings, the same ones eval can.
Is there some documentation that implies that the int, float, etc. constructors are meant to take "human-readable" strings rather than "Python-evaluable" strings? Or some other case I'm missing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140806/54cb523c/attachment.html>
More information about the Python-ideas
mailing list