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

Nick Coghlan ncoghlan at gmail.com
Tue May 27 04:32:24 CEST 2008


Jim Jewett wrote:
> On 5/26/08, Adam Olsen <rhamph at gmail.com> wrote:
>> On Mon, May 26, 2008 at 5:24 PM, Oleg Broytmann <phd at phd.pp.ru> wrote:
> 
>>  >   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]'?
> 
> I don't think anyone is arguing about how to display
> 
>     >>> "%" % string
> 
> The problem is classes where str(x) != repr(x), and how they get
> messed up when a container holding (one of their) instances is
> printed.

This is NOT a bug, since str([1, 2, 3]) and str(list("123")) SHOULD 
produce results that look different. Calling str() internally to display 
the contents of containers is a broken idea. The ambiguity that 
recursive calls to str() would introduce would make any concerns about 
potential confusion between different Unicode glyphs seem utterly 
inconsequential.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list