[Python-Dev] __str__ bug?

Mike Krell mbk.lists at gmail.com
Tue Oct 24 07:22:51 CEST 2006

Is this a bug?  If not, how do I override __str__ on a unicode derived class?

class S(str):
    def __str__(self): return '__str__ overridden'

class U(unicode):
    def __str__(self): return '__str__ overridden'
    def __unicode__(self): return u'__unicode__ overridden'

s = S()
u = U()

print 's:', s
print "str(s):", str(s)
print 's substitued is "%s"\n' % s
print 'u:', u
print "str(u):", str(u)
print 'u substitued is "%s"' % u


s: __str__ overridden
str(s): __str__ overridden
s substitued is "__str__ overridden"

str(u): __str__ overridden
u substitued is ""

Results are identical for 2.4.2 and 2.5c2 (running under windows).


More information about the Python-Dev mailing list