A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2006-August/068395.html below:

[Python-Dev] String formatting / unicode 2.5 bug?

[Python-Dev] String formatting / unicode 2.5 bug? [Python-Dev] String formatting / unicode 2.5 bug?Nick Coghlan ncoghlan at gmail.com
Sun Aug 20 07:03:21 CEST 2006
John J Lee wrote:
> Is this a bug?

I don't believe so - the string formatting documentation states that the 
result will be unicode if either the format string is unicode or any of the 
objects passed to a %s format code is unicode.

That latter part has just been extended to include any object that returns 
Unicode from __str__, instead of being restricted to actual Unicode instances.

Note that the following behaves the same way regardless of whether you use 2.4 
or 2.5:
"%s" % 'hi'
"%s" % u'hi'

And once the result has been promoted to unicode, __unicode__ is used directly:

 >>> print repr("%s%s" % (a(), a()))
__str__
accessing <__main__.a object at 0x00AF66F0>.__unicode__
__str__
accessing <__main__.a object at 0x00AF6390>.__unicode__
__str__
u'hihi'

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
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