Why KeyError ???

Raymond Hettinger python at rcn.com
Tue Mar 5 22:07:38 EST 2002


"Ozren Lasic" <ozren_lasic at yahoo.com> wrote in message
> >>> import sys
> >>> sys.setdefaultencoding("cp1250")
> >>> a = "\xe7\xd0\x9f\x86\xa7" # Croatian characters
> >>> b = unicode(a)
> >>> b
> u'\xe7\u0110\u017a\u2020\xa7'
> >>> c = {}
> >>> c[a] = 1
> >>> c[b]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> KeyError: šđčćž
> >>> a == b
> 1

Hmm.  I don't get the same identity check results as you do:
>>> a = '\xe7\xd0\x9f\x86\xa7'
>>> b = unicode(a,'cp1250')
>>> a is b
0


Raymond Hettinger





More information about the Python-list mailing list