Problems with struct.pack()
Carsten Haese
carsten at uniqsys.com
Wed Oct 10 20:50:55 EDT 2007
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 the encoding of the string returned
> by "pack" isn't unicode. I'm a bit confused right now as to how I can
> get this to work. I can't allow the unicode-ness of the file interfere
> with the actual order of the bytes that pack() is returning (In other
> words, don't pack NULL characters in there)
Please start at the beginning. What are you actually trying to
accomplish and why do you think you need to write arbitrary binary data
into a file that is supposed to be a UTF-16 encoded Unicode text file?
--
Carsten Haese
http://informixdb.sourceforge.net
More information about the Python-list
mailing list