python evaluate string as unicode
This took me a while to figure out:
Let’s define a normal string which should be evaluated as unicode later
s=’at\u0026t’
string to unicode convert function doesn’t help in this case:
>>> unicode(s)
u’at\\u0026t’
Instead we need to decode string with unicode-escape encoding:
>>> s=’at\u0026t’
>>> type(s)
>>> s.decode( ‘unicode-escape’ )
u’at&t’
Filed in Linux, Problemy, Python & Django, Web No Responses yet