Re: Problems with struct.pack()

2007-10-11 Thread Carsten Haese
On Thu, 2007-10-11 at 10:45 -0500, Robert Dailey wrote: > What if 'mystring' has been encoded to "utf-8"? > > mystring = u"Hello World" > mystring = mystring.encode( "utf-8" ) > > So far the code above doesn't seem to work with this. Why would you encode the string into UTF-8? Didn't you say tha

Re: Problems with struct.pack()

2007-10-11 Thread Robert Dailey
On 10/11/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > > This is much clearer, and it explains why you need to mix arbitrary binary > data with unicode text. Because of this mixing, as you have surmised, > you're > going to have to treat the file as a binary file in Python. In other > words, > don

Re: Problems with struct.pack()

2007-10-11 Thread Carsten Haese
On Wed, 10 Oct 2007 22:19:49 -0500, Robert Dailey wrote > Hi, > > Thanks for responding. I apologize about my lack of details, I was in a hurry when I wrote the initial question. I'll provide more details. > > Basically, I'm attempting to write out unicode strings (16 bits per character) to a

Re: Problems with struct.pack()

2007-10-10 Thread Robert Dailey
Hi, Thanks for responding. I apologize about my lack of details, I was in a hurry when I wrote the initial question. I'll provide more details. Basically, I'm attempting to write out unicode strings (16 bits per character) to a file. Before each string, I write out 4 bytes containing the number o

Re: Problems with struct.pack()

2007-10-10 Thread Carsten Haese
On Wed, 2007-10-10 at 19:00 -0500, Robert Dailey wrote: > Hi, > > I have opened a unicode file for writing: > > import codecs > file = codecs.open( "somefile.dat", "wb", "utf-16" ) > > and I attempt to do this: > > file.write( struct.pack ( "I", 5000 ) ) > > However, this won't work because th

Problems with struct.pack()

2007-10-10 Thread Robert Dailey
Hi, I have opened a unicode file for writing: import codecs file = codecs.open( "somefile.dat", "wb", "utf-16" ) and I attempt to do this: file.write( struct.pack( "I", 5000 ) ) However, this won't work because the encoding of the string returned by "pack" isn't unicode. I'm a bit confused rig