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/2006-October/069554.html below:

[Python-Dev] __str__ bug?

[Python-Dev] __str__ bug? [Python-Dev] __str__ bug?Mike Krell mbk.lists at gmail.com
Tue Oct 24 07:22:51 CEST 2006
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

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