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/048490.html below:

[Python-Dev] unicode and __str__

[Python-Dev] unicode and __str__ [Python-Dev] unicode and __str__"Martin v. Löwis" martin at v.loewis.de
Mon Aug 30 23:35:17 CEST 2004
Neil Schemenauer wrote:
> But unicode() will also return __str__, eg.
> 
>     >>> class A:
>     ...   def __str__(self): 
>     ...     return u'\u1234'
>     ... 
>     >>> unicode(A())
>     u'\u1234'
> 
> Why would I want to use __unicode__?  

This class is incorrect: it does not support str().

> Shouldn't we be heading to a
> world where __str__ always returns unicode objects?

No. In some cases, str() needs to compromise, where unicode() doesn't.

> Now, say your class stores unicode character data.  You could have
> __unicode__ return a unicode object and have __str__ encode it
> somehow and return a str.  However, that seems like a horrible
> design to me.

Perhaps. What are you proposing to do about this? Ban, from the face
of the earth, what seems like a horrible design to you?

Regards,
Martin
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