[Python-Dev] __str__ vs. __unicode__
Walter Dörwald
walter at livinglogic.de
Tue Jan 18 16:05:42 CET 2005
__str__ and __unicode__ seem to behave differently. A __str__
overwrite in a str subclass is used when calling str(), a __unicode__
overwrite in a unicode subclass is *not* used when calling unicode():
-------------------------------
class str2(str):
def __str__(self):
return "foo"
x = str2("bar")
print str(x)
class unicode2(unicode):
def __unicode__(self):
return u"foo"
x = unicode2(u"bar")
print unicode(x)
-------------------------------
This outputs:
foo
bar
IMHO this should be fixed so that __unicode__() is used in the
second case too.
Bye,
Walter Dörwald
More information about the Python-Dev
mailing list