[ python-Bugs-971106 ] Comparisons of unicode and strings raises UnicodeErrors

SourceForge.net noreply at sourceforge.net
Mon Jun 14 12:16:16 EDT 2004


Bugs item #971106, was opened at 2004-06-11 15:07
Message generated for change (Comment added) made by ctheune
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=971106&group_id=5470

Category: Unicode
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Christian Theune (ctheune)
Assigned to: M.-A. Lemburg (lemburg)
Summary: Comparisons of unicode and strings raises UnicodeErrors

Initial Comment:
When comparing unicode and strings the implicit conversion
will raise an exception instead of returning false. See the
example later on.

We (Christian Theune and Jim Fulton) suggest that
if the ordinary string can't be decoded,  that False should
be returned.  This seems to be the only sane approach 
given's Python's policy of implicitly converting strings
to unicode using a default encoding.


Python 2.3.4 (#1, Jun 10 2004, 11:08:42) 
[GCC 3.3.3 20040412 (Gentoo Linux 3.3.3-r6,
ssp-3.3.2-2, pie-8.7.6)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> class Elephant:
...     pass
... 
>>> e1 = Elephant()
>>> e1 == 5
False
>>> u"asdf" == "asdfö"
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte
0xf6 in position 4: ordinal not in range(128)
>>> e1 == "asdfö"
False
>>> e1 == u"asdfö"
False
>>> 


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

>Comment By: Christian Theune (ctheune)
Date: 2004-06-14 18:16

Message:
Logged In: YES 
user_id=100622

That's what Jim and I found to be the best solution (for now) 

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

Comment By: M.-A. Lemburg (lemburg)
Date: 2004-06-14 18:06

Message:
Logged In: YES 
user_id=38388

I'm not sure what you are suggesting here... do you want
u"asdf" == "asdfö" to return False ?

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

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



More information about the Python-bugs-list mailing list