Problems with struct.pack()

Robert Dailey rcdailey at
Thu Oct 11 02:00:09 CEST 2007


I have opened a unicode file for writing:

import codecs
file = "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)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list