[Python-Dev] __str__ and unicode
Michael Urman
murman at gmail.com
Wed Dec 6 15:15:29 CET 2006
> I don't have anything older than 2.4 laying around either, but IIRC
> in 2.3 unicode() did not call __unicode__().
It turns out __unicode__() is called on Python 2.3.5.
% python2.3
Python 2.3.5 (#2, Oct 18 2006, 23:04:45)
[GCC 4.1.2 20061015 (prerelease) (Debian 4.1.1-16.1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
... def __unicode__(self):
... print "unicode"
... return u"hi"
... def __str__(self):
... print "str"
... return "hello"
...
>>> unicode(Foo())
unicode
u'hi'
--
Michael Urman http://www.tortall.net/mu/blog
More information about the Python-Dev
mailing list