I've got some data stored as strings that contains both unicode characters (e.g., ñ
) and unicode escape sequences (e.g., \u00F1
). I would like to do a string-to-string transformation that converts the escape sequences into the corresponding unicode characters. For example, if the string is s = r'\u00F1ñ'
, I would like the output to be 'ññ'
.
The closest I've found so far is s.encode().decode('unicode-escape')
: this converts the escape sequences, but mangles any unicode characters already present.
Please note that this question is for python 3.