[Python-Dev] Decimal conversion to string

Guido van Rossum guido at python.org
Thu Apr 15 09:55:56 EDT 2004


> But who cares about the gory details of the internals?
> The most important thing about a repr() is to unambiguously
> indicate the object's type; the next is to show something
> about its value, as far as reasonably possible. What's
> actually inside the object doesn't matter much.

I didn't see the start of this, but the guidelines for repr() are and
have always been this: if at all possible it should be an expression
that, when fed to eval(), (assuming the right imports are in scope),
returns an object with the same type and value.  In most cases, this
means it should resemble a call to the constructor with suitable
arguments.  If that isn't possible, a form surrounded with <...>
should be used, and it should at least show the object's type and some
stuff that can be used to distinguish different instances (either the
address or some representative property of the instance).

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list