Skip to content
Advertisement

How do I decode escaped unicode javascript code in Python?

I have this string:

JavaScript

Which should read “V posledních měsících se …” so u00ed is í and u011b is ě.

Any idea how to decode this in Python? It is a javascript code I am parsing in python. I could write my own ad-hoc solution as there are not that many characters that are escaped (there are only twelve or so accented characters in Czech), but that seems ugly.

Advertisement

Answer

Decode it using the 'unicode-escape' codec. If x is your string, x.decode('unicode-escape').

Advertisement