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/2004-August/048510.html below:

[Python-Dev] unicode and __str__

[Python-Dev] unicode and __str__ [Python-Dev] unicode and __str__Neil Schemenauer nas at arctrix.com
Tue Aug 31 20:41:16 CEST 2004
On Tue, Aug 31, 2004 at 10:23:33AM +0200, M.-A. Lemburg wrote:
> __str__ is indeed allowed to return Unicode objects
> (and has been for quite a while).
[...]
> Now back to your original question: the change you see
> in %-formatting was actually a bug fix. Python 2.3 should
> have exposed the same behavior as 2.4 does now.

I think the note in NEWS is not quite accurate.  It says:

    Let u'%s' % obj try obj.__unicode__() first and fallback to
    obj.__str__().

The change in PyUnicode_Join replaces a PyObject_Str() call with
PyObject_Unicode().  That means that this works in 2.4:

    class A:
        def __str__(self):
            return u'\u1234'

    u'%s' % A()

Perhaps that is unintentional but it seems cleaner to me than adding
a __unicode__ method and not providing a __str__ method.

  Neil
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