[Python-ideas] Python Numbers as Human Concept Decimal System

Mark H. Harris harrismh777 at gmail.com
Sat Mar 8 17:13:39 CET 2014


On Saturday, March 8, 2014 2:16:26 AM UTC-6, Andrew Barnert wrote:
>
> I think you're a little confused here.
>
>  repr() doesn't act like an eval(). It's sort of an _inverse_ of eval, for 
> some types.[1] For example, the repr of Decimal('0.1') is the string 
> "Decimal('0.1')", and eval("Decimal('0.1')") will give you Decimal('0.1').
>
You are correct, I was confused about the inverse relationship, for some 
types, because the http doc says:

                 For many types, this function makes an attempt to return a 
string that would 

                  yield an object with the same value when passed to eval(),

But,  the system doc help() makes things more clear:

repr(...)
    repr(object) -> string
    
    Return the canonical string representation of the object.
    For most object types, eval(repr(object)) == object.



Thank you,  your explanation of the caveats for repr() were helpful to me.

marcus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140308/5a735ce8/attachment.html>


More information about the Python-ideas mailing list