I am trying to convert an plain string into the special character to work it in my logic in python 2.
word = 'Tb\u03b1'
word = unicode('Tb\u03b1')
if word.encode('utf-8') == u'Tb\u03b1'.encode('utf-8'):
print 'They are equals'
The problem is that
\u has no special meaning in a non-unicode literal, so it remains as
\u in your string. To interpret the
\u escapes and produce the corresponding Unicode, use the encoding
>>> as_str = "\u03b1" >>> as_unicode = as_str.decode(encoding="unicode_escape") >>> print as_unicode α
But you'd be better off if you could figure out a way to avoid being in this situation. Even better, switch to Python 3 where these kinds of things make a lot more sense.