[BioPython] byte packing and binary files

Scott T. Kelley kelleys@ucsu.colorado.edu
Mon, 8 Jan 2001 10:23:28 -0800


Dear Biopythoneers,

I have an unusual question about writing binary files. I have some data that
I want make available to someone else's program written in C++ on a Mac (he
has a nice GUI all set up) and the easiest way for his program to read the
input would be if all the numbers were read in as 8 byte doubles.

I know you can use the struct library to pack numbers as doubles: pack('d',
number) but can you then write these to a binary file easily? Is there
another way to do this that I don't know about?

The file I want to write is just a list of number (two ints and a float)
that looks like this:

2    5    8.9035
2    7    10.988

...etc.

Thanks for any pointers you can send my way. -Scott

-------------------
Scott T. Kelley, Ph.D.
Campus Box 347
MCD Biology
University of Colorado
Boulder, CO 80309-0347
Phone: (303) 735-1808
Fax: (303) 492-7744
E-mail: Scott.Kelley@Colorado.edu