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

Adam Olsen rhamph at gmail.com
Tue May 27 02:00:02 CEST 2008


On Mon, May 26, 2008 at 5:24 PM, Oleg Broytmann <phd at phd.pp.ru> wrote:
> On Mon, May 26, 2008 at 06:53:41PM -0400, Jim Jewett wrote:
>> I certainly support a flag for repr meaning "This was really str; repr
>> got called because the container doesn't have str, but go back to str
>> for the contents."  (Alternatively, write an explicit repr that does
>> that, add it to the builtin types, and make it available for easy use
>> with extensions.)
>>
>> > Exceptions use repr() for file names,
>> >  e.g., which is very inconvenient, IMHO.
>>
>> I'm not sure I fully understand this problem, but I would expect the
>> right solution to be a change to either Exception.__str__ or the way
>> filename-related exceptions are initialized.  Changing all of repr is
>> again overkill.
>
>   There are two different and unrelated problems. One is that
> str(container) calls repr() on items. This probably could be fixed with
> a flag to repr() so it remembers it was called from str(). This has nothing
> with hex-encoding strings - calling str() on items would be a win in any
> case, especially for items that implements both __str__ and __repr__
> methods.

There's a reason for that convention.  Would you prefer str(['1', '2',
'3']) return '[1, 2, 3]'?

Personally, I'm happy with Guido's suggestion of stderr and
interactive to backslashreplace and stdout to strict.  It's a dramatic
change, but I think I can get used to it.

-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-3000 mailing list