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 <[EMAIL PROTECTED]>
>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
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com