Need help on UNICODE conversion

Bernd Preusing b.preusing at web.de
Sat Sep 6 15:07:59 EDT 2003


Hi,

today I (Python beginner) ran into a problem:^

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).

How do I convert such string to a real unicode string and to
a windows_1252 or latin1 afterwards? I know it's a text with
german umlauts.

I tried this:
if rawdata[:7] == "UNICODE":
                ustring = rawdata[7:]
                us2 = unicode(ustring, "windows_1252")
                as2 = us2.encode("windows_1252")
                self.dic["ComUNI"] = rawdata

But all I get on each stage is a normal string with lots of  \\0x00.

TIA
  Bernd





More information about the Python-list mailing list