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

Neil Schemenauer nas at arctrix.com
Sun Aug 20 18:39:29 CEST 2006


John J Lee <jjl at pobox.com> wrote:
> The note (4) says that the result will be unicode, but it doesn't say how, 
> in this case, that comes about.  This case is confusing because the docs 
> claim string formatting with %s "converts ... using str()", and yet 
> str(a()) returns a bytestring.  Does it *really* use str, or just __str__? 
> Surely the latter? (given the observed behaviour, and not reading the C 
> source)

It uses __str__ and confirms that the returned object is a 'str' or
'unicode'.  The docs are not precise but they were not for 2.4
either.  Note the following case:

    '%s' % u'Hello!'

The operand is not forced to be a str.

  Neil



More information about the Python-Dev mailing list