comparing Unicode and string
luc.saffre at gmail.com
luc.saffre at gmail.com
Mon Oct 16 09:26:07 EDT 2006
Hello,
here is something that surprises me.
#coding: iso-8859-1
s1=u"Frau Müller machte große Augen"
s2="Frau Müller machte große Augen"
if s1 == s2:
pass
Running this code produces a UnicodeDecodeError:
Traceback (most recent call last):
File "tmp.py", line 4, in ?
if s1 == s2:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 6:
ordinal not in range(128)
I would have expected that "s1 == s2" gives True... or maybe False...
but raising an error here is unnecessary. I guess that the comparison
operator decides to convert s2 to a Unicode but forgets that I said
#coding: iso-8859-1 at the beginning of the file.
TIA for any comments.
Luc Saffre
More information about the Python-list
mailing list