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

Oleg Broytmann phd at phd.pp.ru
Tue May 27 08:29:47 CEST 2008


On Tue, May 27, 2008 at 12:48:08PM +1000, Nick Coghlan wrote:
> Jim Jewett wrote:
> >Is it again because of the bug where str([..., mystr, ...])   ends up
> >doing repr on mystr?
> 
> Jim, could you please stop describing this behaviour as a bug?

   I am with  Jim on this part (but only on this). I'd like this

class Test:
    def __str__(self):
        return "STR"

    def __repr__(self):
        return "REPR"

test = Test()
print test
print repr(test)
print str(test)
print [test]
print str([test])
print repr([test])

   to print

STR
REPR
STR
[STR]
[STR]
[REPR]

   but the code actually prints

STR
REPR
STR
[REPR]
[REPR]
[REPR]

   str(container) not calling str() on items is at least a strange and
unexpected behaviour, if not a bug.
   Unfortunately, it is not easy to fix, and missing quotes on string items
is a loose (albeit a minor one for me), so I accepted the compromise - to
fix repr() and forget about str(container).

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