1) How can I convert a symbol to its 4 digit Unicode escape representation in python 2.7
e.g "¥"
to "\u00a5"
?
2) How can I convert a Unicode representation to the symbol notation on Windows 7/8 platform
e.g "\u00a5"
to "¥"
?
1) How can I convert a symbol to its 4 digit Unicode escape representation in python 2.7
e.g "¥"
to "\u00a5"
?
2) How can I convert a Unicode representation to the symbol notation on Windows 7/8 platform
e.g "\u00a5"
to "¥"
?
1) Does it need to be
\u
-escaped? Will\x
work? If so, try theunicode_escape
codec. Otherwise, you can convert using the function below:2) Similarly, you can use the
unicode_escape
codec:The most reliable way I found to do this in python is to first decode it into unicode, get the
ord
of the unicode character and plug that into a format string. It looks like this:There is also a method
unichr
that is supposed to output something like this, but on my system it displays a different encoding than what the op wanted. So the above solution is the most platform independent way that I can think of.