Syver Enstad wrote:

> David Ascher <[EMAIL PROTECTED]> writes:
>
> > Use 'struct.pack' and then write to a file opened in binary mode
> > open('foo.dat', 'wb').write(struct.pack(...))
>
> You can also just specify bytes in a string and write it to the file,
> like this:
> open('foo.dat', 'wb').write('\x0\x1')
>
> (Which is just what struct.pack in a more elegant fashion)

The real advantage of using struct.pack() comes when writing data that uses
multiple bytes per item, such as 32-bit ints.  If you're specifying the bytes
yourself, you have to worry about little-endian vs. big-endian, and all of that
sort of mess, but struct.pack() handles that for you transparently.

Jeff Shannon
Technician/Programmer
Credit International


_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython

Reply via email to