python raw_input odd behavior with accents containing strings
Posted
by
Ryan
on Stack Overflow
See other posts from Stack Overflow
or by Ryan
Published on 2012-06-17T02:51:13Z
Indexed on
2012/06/17
3:16 UTC
Read the original article
Hit count: 428
I'm writing a program that asks the user for input that contains accents. The user input string is tested to see if it matches a string declared in the program. As you can see below, my code is not working:
code
# -*- coding: utf-8 -*-
testList = ['má']
myInput = raw_input('enter something here: ')
print myInput, repr(myInput)
print testList[0], repr(testList[0])
print myInput in testList
output in eclipse with pydev
enter something here: má
mv° 'm\xe2\x88\x9a\xc2\xb0'
má 'm\xc3\xa1'
False
output in IDLE
enter something here: má
má u'm\xe1'
má 'm\xc3\xa1'
Warning (from warnings module):
File "/Users/ryanculkin/Desktop/delete.py", line 8
print myInput in testList
UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
False
How can I get my code to print True when comparing the two strings?
Additionally, I note that the result of running this code on the same input is different depending on whether I use eclipse or IDLE. Why is this? My eventual goal is to put my program on the web; is there anything that I need to be aware of, since the result seems to be so volatile?
© Stack Overflow or respective owner