Python - converting wide-char strings from a binary file to Python unicode strings...
Posted
by Mikesname
on Stack Overflow
See other posts from Stack Overflow
or by Mikesname
Published on 2010-04-30T17:27:58Z
Indexed on
2010/04/30
23:37 UTC
Read the original article
Hit count: 291
It's been a long day and I'm a bit stumped.
I'm reading a binary file that contains lots of wide-char strings and I want to dump these out as Python unicode strings. (To unpack the non-string data I'm using the struct module, but I don't how to do the same with the strings.)
For example, reading the word "Series":
myfile = open("test.lei", "rb")
myfile.seek(44)
data = myfile.read(12)
# data is now 'S\x00e\x00r\x00i\x00e\x00s\x00'
How can I encode that raw wide-char data as a Python string?
Edit: I'm using Python 2.6
© Stack Overflow or respective owner