18 Jan
2005
18 Jan
'05
7:05 a.m.
__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
6971
Age (days ago)
7009
Last active (days ago)
18 comments
7 participants
participants (7)
-
Aahz
-
Alex Martelli
-
Bob Ippolito
-
Brett C.
-
M.-A. Lemburg
-
Nick Coghlan
-
Walter Dörwald