[Python-bugs-list] [ python-Bugs-438164 ] Format operator % fails with unicode

noreply@sourceforge.net noreply@sourceforge.net
Tue, 20 Nov 2001 07:20:05 -0800


Bugs item #438164, was opened at 2001-07-03 00:58
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=438164&group_id=5470

Category: Python Interpreter Core
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Chema Cortés (chemacortes)
Assigned to: M.-A. Lemburg (lemburg)
Summary: Format operator % fails with unicode

Initial Comment:
A dictionary with unicode keys raise an error when it 
is applied to a string throught the format operator %.

Here is the ofending code:

>>> "%(año)d" % { u"año":2001 }  # KeyError: año

This fails because u"año" and "año" cannot be 
compared: byte strings and Unicode strings are 
comparable only if the byte string is ASCII.

> >>> u"%(año)4d" % { u"año":2001 }  # KeyError: año

This fails because the key is converted to UTF-8 
before lookup.


Must be add the unicode case into the format operator %

----------------------------------------------------------------------

>Comment By: M.-A. Lemburg (lemburg)
Date: 2001-11-20 07:20

Message:
Logged In: YES 
user_id=38388

Ok, decided to go with the all Unicode solution. Patch already checked in.

----------------------------------------------------------------------

Comment By: M.-A. Lemburg (lemburg)
Date: 2001-11-20 06:20

Message:
Logged In: YES 
user_id=38388

The first case cannot be fixed since there's no way to magically know that the lookup string is in Latin-1.

The second is slightly different: this was from the very beginning of the Unicode implementation where we used 
UTF-8 as default encoding. I'll have to think about this some more, but I believe that we should drop the conversion 
altogether and use the Unicode object for the lookup rather than converting it to a string.


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-09-05 11:02

Message:
Logged In: YES 
user_id=6380

Wow, that's some vacation! :-)

----------------------------------------------------------------------

Comment By: M.-A. Lemburg (lemburg)
Date: 2001-08-16 03:47

Message:
Logged In: YES 
user_id=38388

I'll look into this after I'm back from vacation on the 10.09.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=438164&group_id=5470