[Pythonmac-SIG] writing binary files with MacPython

Jack Jansen jack@oratrix.nl
Mon, 19 Feb 2001 10:23:11 +0100


> I'm using MacPython 2.0 under Mac OS 8.5.1 and I'm having trouble with
> creating binary files of short ints using MacPython.  As a small
> example:
> 
> >>> from array import array
> >>> a = array('h', [2678, 2689, 2699])
> >>> open('tmp', 'w').write(a.tostring())

If you open a binary file you should specify 'wb' as the flag (or 'rb' for 
reading). On Unix this isn't important, but on Mac and Windows it is.
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack    | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm