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

Oleg Broytmann phd at phd.pp.ru
Tue May 27 10:36:13 CEST 2008


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().

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-3000 mailing list