[Python-3000] PEP 3138- String representation in Python 3000

M.-A. Lemburg mal at egenix.com
Tue May 27 12:35:04 CEST 2008


On 2008-05-27 05:02, Stephen J. Turnbull wrote:
> Jim Jewett writes:
> 
>  > The only reason for this change is that __repr__ gets used when
>  > __str__ *should* be used instead.
> 
> That's not what the advocates say.
> 
> Now, repr() is supposed to return something that is acceptable to eval
> (but doesn't always, especially for recursive objects), while str() is
> supposed to be more "user-friendly" (but can be horrible if you need
> to see precisely what the contents are or on an output device that's
> not prepared for it).

AFAIK, eval(repr(obj)) is no longer a requirement... simply because
it has always only worked for a small subset of objects and in
reality, you wouldn't want to call eval() on anything too often
due to the security implications.

In my daily use, I see repr(obj) as a way to get a debugging text
view of an object, whereas str(obj) is a way to convert it into text.

If an object doesn't have a special debugging text view, then it's
fine to use the standard text view instead.

> As far as I can tell, which should be used is a "beauty in the eye of
> the beholder" issue, and in the case of repr() Spanish and Chinese
> users are going to feel more or less differently from Americans about
> which characters should be escaped.

I'm not sure that's always the case, but users should certainly
have the freedom to decide whether they prefer backslashed quoted
code points or glyphs on their screen.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 27 2008)
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2008-07-07: EuroPython 2008, Vilnius, Lithuania            40 days to go

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::


    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
            Registered at Amtsgericht Duesseldorf: HRB 46611


More information about the Python-3000 mailing list