[Python-Dev] str bug? (original) (raw)

Tamito KAJIYAMA RD6T-KJYM at asahi-net.or.jp
Tue Oct 24 21:41:27 CEST 2006


I believe you've overriden unicode.str as you expect.

class S(str): def str(self): return "S.str"

class U(unicode): def str(self): return "U.str"

print str(S()) print str(U())

This script prints:

S.str U.str

Regards,

-- KAJIYAMA, Tamito <RD6T-KJYM at asahi-net.or.jp>

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" u: str(u): str overridden u substitued is "" Results are identical for 2.4.2 and 2.5c2 (running under windows). Mike



More information about the Python-Dev mailing list