converting to and from octal escaped UTF--8
Michael Goerz
answer654 at 8439.e4ward.com
Sun Dec 2 20:17:50 EST 2007
Hi,
I am writing unicode stings into a special text file that requires to
have non-ascii characters as as octal-escaped UTF-8 codes.
For example, the letter "Í" (latin capital I with acute, code point 205)
would come out as "\303\215".
I will also have to read back from the file later on and convert the
escaped characters back into a unicode string.
Does anyone have any suggestions on how to go from "Í" to "\303\215" and
vice versa?
I know I can get the code point by doing
>>> "Í".decode('utf-8').encode('unicode_escape')
but there doesn't seem to be any similar method for getting the octal
escaped version.
Thanks,
Michael
More information about the Python-list
mailing list