[Python-3000] str(container) calls repr()
Oleg Broytmann
phd at phd.pp.ru
Tue May 27 11:57:09 CEST 2008
On Tue, May 27, 2008 at 07:28:42PM +1000, Nick Coghlan wrote:
> The problem arises whenever you have two different objects which can
> produce the same answer for str(), but different answers for repr().
Aside strings itself, the only example of such objects I can imagine is
numbers (ints, floats and decimals). str(12) is the same as str('12') and
the same as str(Decimal('1')), but that's all.
> All I'm really asking for here is for people to identify the use cases
> that justify introducing such a potential for ambiguity into the
> container implementations.
Why do you afraid of ambiguity so much? str() is supposed to produce
pretty output, not necessary non-ambiguous, tight? And if a user wants
non-ambiguity [s]he will use repr().
> I've yet to see
> *any* specific use cases for containers invoking str() that wouldn't be
> better addressed with an application or library specific display loop.
Unfortunately, every library has to have its own specific loop, because
universal container traversing is impossible.
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