Problems with struct.pack()

Robert Dailey rcdailey at gmail.com
Wed Oct 10 20:00:09 EDT 2007


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)

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071010/06891b81/attachment.html>


More information about the Python-list mailing list