[Python-Dev] String formatting / unicode 2.5 bug? (original) (raw)

John J Lee jjl at pobox.com
Tue Aug 22 19:42:02 CEST 2006


On Mon, 21 Aug 2006, Nick Coghlan wrote:

John J Lee wrote:

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' I don't understand this part. Why is unicode called? Your example doesn't appear to show this happening "once [i.e., because?] the result has been promoted to unicode" -- if that were true, it would "stand to reason" that the interpreter would then conclude it should call unicode for all remaining %s, and not bother with str. It does try to call unicode directly, but because the example object doesn't supply unicode it ends up falling back to str instead. The behaviour is clearer when the example object provides both methods: [...]

If the interpreter is falling back from unicode to str (rather than the other way around, kind-of), that makes much more sense. I understood that unicode was not provided, of course -- what wasn't clear to me was why the interpreter was calling/accessing those methods/attributes in the sequence it does. Still not sure I understand what the third str above comes from, but until I've thought it through again, that's my problem.

John



More information about the Python-Dev mailing list