[Python-3000] str(container) calls repr() (was: PEP 3138)

Guido van Rossum guido at python.org
Tue May 27 19:04:45 CEST 2008


On Tue, May 27, 2008 at 1:36 AM, Oleg Broytmann <phd at phd.pp.ru> wrote:
> On Tue, May 27, 2008 at 06:13:39PM +1000, Nick Coghlan wrote:
>> str([1, 2, 3]), str(list("123")) and str(["1, 2, 3"]) should all produce
>> distinctive output: calling repr() on container contents achieves this,
>> calling str() does not.
>
>   String representation is a special case and *the only* special case, and
> must be handled as a special case. I don't like this special case to be used
> as a model for all other types. No other type allows usage like list("123").
>
>> While it could be argued that if you want unambiguous output you should
>> be invoking repr() on the container instead of str(), I'm still seeing
>> many more downsides than upsides to the idea of making str() on the
>> builtin containers display their contents with str() instead of repr().
>
>   The decision should be upon the user. In an ideal world str(container)
> calls str() on items, and repr(container) calls repr() on items, so the
> user can choose what [s]he wants. Currently user is just stuck with repr().

I disagree. Calling str() on items is counterproductive.

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


More information about the Python-3000 mailing list