Re: Unicode strings, struct, and files

2006-10-09 Thread John Machin
Tom Plunket wrote: I am building a file with the help of the struct module. I would like to be able to put Unicode strings into this file, but I'm not sure how to do it. The format I'm trying to write is basically this C structure: struct MyFile { int magic; int flags; short

Re: Unicode strings, struct, and files

2006-10-09 Thread Tom Plunket
John Machin wrote: message = unicode('Hello, world') myFile.write(message) results in 'message' being converted back to a string before being written. Is the way to do this to do something hideous like this: for c in message: myFile.write(struct.pack('H', ord(unicode(c

Unicode strings, struct, and files

2006-10-08 Thread Tom Plunket
I am building a file with the help of the struct module. I would like to be able to put Unicode strings into this file, but I'm not sure how to do it. The format I'm trying to write is basically this C structure: struct MyFile { int magic; int flags; short otherFlags; char pad[22];