David Ascher <[EMAIL PROTECTED]> writes: > John Mark Agosta wrote: > > > > > Where is there a Python function to write binary data directly > > instead of ascii (or other encodings)? The pickle module binary > > format is specific to pickle - that doesn't count, I want to be able > > > to specify the individual bytes written to a file. > > Use 'struct.pack' and then write to a file opened in binary mode > open('foo.dat', 'wb').write(struct.pack(...)) >
Yes, that is probably the most elegant way of doing it. 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) -- Vennlig hilsen Syver Enstad _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython