Unicode and dictionaries
Carl Banks
pavlovevidence at gmail.com
Sat Jan 16 20:38:43 EST 2010
On Jan 16, 3:58 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Sat, 16 Jan 2010 15:35:05 -0800, gizli wrote:
> > Hi all,
>
> > I am using Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41). I ran
> > into this issue yesterday and wanted to check to see if this is a
> > python bug. It seems that there is an inconsistency between lists and
> > dictionaries in the way that unicode objects are handled. Take a look at
> > the following example:
>
> >>>> test_dict = {u'öğe':1}
> >>>> u'öğe' in test_dict.keys()
> > True
> >>>> 'öğe' in test_dict.keys()
> > True
>
> I can't reproduce your result, at least not in 2.6.1:
>
> >>> test_dict = {u'öğe':1}
> >>> u'öğe' in test_dict.keys()
> True
> >>> 'öğe' in test_dict.keys()
>
> __main__:1: UnicodeWarning: Unicode equal comparison failed to convert
> both arguments to Unicode - interpreting them as being unequal
> False
The OP changed his default encoding. I was able to confirm the
behavior after setting the default encoding to latin-1.
This is most definitely a bug in Python.
Carl Banks
More information about the Python-list
mailing list