python - How should I convert a string containing unicode characters to unicode? -
i thought dominated unicode stuff in python 2, seems there's don't understand. have user input html goes python script:
a = "m\xe9dico"
i want médico
(that means doctor). convert unicode i'm doing:
a.decode("utf-8")
or:
unicode(a, "utf-8")
but throwing:
unicodeencodeerror: 'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128)
how can achieve this?
this not utf-8:
print txt.decode('iso8859-1') out[14]: médico
if want utf-8 string, use:
txt.decode('iso8859-1').encode('utf-8') out[15]: 'm\xc3\xa9dico'
Comments
Post a Comment