How Do I Solve The Unicodewarning Issue?
I spent about four hours researching the 'UnicodeWarning: Unicode unequal comparison' issue. Usually, after a few hours, I'm able to answer my trickiest questions by myself, but th
Solution 1:
First, read this: http://www.joelonsoftware.com/articles/Unicode.html
Then - you should not really use iso-8859-1
encoding when dealing with Python in whatever system - use utf-8
instead.
Third, your easygui
component is returning you a unicode object instead of a byte-string. The easiest way to fix that in the above code is to make the actual_answer
variable an unicode object, but prefixing an "u" to the quotes, like in:
actual_answer = u"pureté"
Solution 2:
Here's a function to return proper utf-8
formatting:
defutf8(str):
return unicode(str, 'latin1').encode('utf-8')
Also, have you tried using unicode escapes?
print"puret\u00E9".decode("unicode_escape")
For example you can apply this to your code as so:
# coding: iso-8859-1import sys
from easygui import *
actual_answer = "puret\u00E9".decode("unicode_escape")
answer_given = enterbox("Type your answer!\n\nHint: " + actual_answer)
if answer_given == actual_answer:
msgbox("Correct! The answer is " + actual_answer)
else:
msgbox("Bug!")
Refer to Python docs for more detailed information on Unicode Escapes. http://docs.python.org/2/howto/unicode.html
Post a Comment for "How Do I Solve The Unicodewarning Issue?"