Need help on UNICODE conversion

Peter Otten __peter__ at web.de
Sat Sep 6 17:29:06 EDT 2003


Bernd Preusing wrote:

> I have a JPG file which contains some comment as unicode.
> 
> After reading in the string with s=file.read(70) from file offest 4
> I get a string which is shown as
> 'UNICODE\\0x00\\ox00K\\0x00o' and so forth in the debugger
> (using Komodo).

Seems that this is not properly cut and pasted :-( 

I suppose that "\\0x00" is just a complicated replacement for "\x00" used by
the debugger. As long as all characters are in the range 0..255, you could
simply remove every other character:

>>> "XHXeXlXlXoX XWXoXrXlXd"[1::2] 
'Hello World'
>>>

Use 8 instead of 1 as start index to also remove "UNICODE".
That might eliminate the need for a unicode string, or you could easily
create one from the "normal" string.


Peter




More information about the Python-list mailing list