This returns False, because the first one is a Str object and the second one is a Unicode object.
However, since they are both Ramón, what can I do so that it returns True.
I’ve tried to convert the first one to a Unicode object:
>>> varString = 'Ramón'
>>> varUnicode = u'Ramón'
>>> varString == varUnicode
False
>>> newUnicode == unicode(varString, encoding='unicode-escape')
>>> varString; varUnicode; newUnicode
'Ram\xa2n'
u'Ram\xf3n'
u'Ram\xa2n'
>>> varUnicode == newUnicode
False
They have different encodings. What can I do? Thanks!
varStringis unlikely to be encoded inunicode-escape. The Python interpreter uses the encoding ofsys.stdin.encodingwhen it decodes what it reads at the>>>prompt into aunicodeobject. So you can use the same encoding when you decode yourstrobject for yourself: