A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-January/051175.html below:

[Python-Dev] __str__ vs. __unicode__

[Python-Dev] __str__ vs. __unicode__ [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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4