str() for containers

Edward C. Jones edcjones at erols.com
Sat Jun 19 11:01:28 EDT 2004


John Roth wrote:
> "George Sakkis" <gsakkis at rutgers.edu> wrote in message
>>I find the string representation behaviour of builtin containers
>>(tuples,lists,dicts) unintuitive in that they don't call recursively str()
>>on their contents (e.g. as in Java) :
> The only clean solution I can see is to provide a third built-in
> that provides the "right" output when a container class needs
> to turn an object into a string. However, someone else
> is going to have to do the work of writing up the use
> cases and the PEP - I don't care enough.

For str of a container, I suggest using repr for strings in the 
container and str for everything else.



More information about the Python-list mailing list