Convert unicode escape sequences to unicode in a file
Jeremy
jlconlin at gmail.com
Tue Jan 11 18:39:15 EST 2011
On Tuesday, January 11, 2011 3:36:26 PM UTC-7, Alex wrote:
>
> Are you _sure_ that your file contains the characters '\', 'u', '0',
> '0', 'e' and '9'? I expect that actually your file contains a byte
> with value 0xe9 and you have inspected the file using Python, which
> has printed the byte using a Unicode escape sequence. Open the file
> using a text editor or hex editor and look at the value at offset 947
> to be sure.
>
> If so, you need to replace 'unicode-escape' with the actual encoding
> of the file.
Yeah, I'm sure that's what the file contains. In fact, I solved my own problem while waiting for an answer. When writing to the file I need to *en*code instead of *de*code; i.e.,
o = open('newDice.sql', 'w')
o.write(utFound.encode('utf-8'))
o.close()
That works!
More information about the Python-list
mailing list