[newbie] Saving binaries in a specific way

Chris Kaynor ckaynor at zindagigames.com
Mon Dec 16 23:28:18 CET 2013

On Mon, Dec 16, 2013 at 2:19 PM, Djoser <pedrovg000 at gmail.com> wrote:

> Hi all,
> I am new to this forum and also to Python, but I'm trying hard to
> understand it  better.
> I need to create a binary file, but the first 4 lines must be in
> signed-Integer16 and all the others in signed-Integer32. I have a program
> that does that with Matlab and other with Mathematica, but I'm converting
> all for Python.
> I tried first to convert the number to binary using 'bin(number'), than I
> removed the '0b' and converted to 'Int16' or 'Int32', but with this
> approach I can't save a binary file using 'bytearray(')

How can I do that?

What you probably want is to use the struct module:

You probably also want the open method and file objects:

It would help if you provided information about which Python version you
are using, and exactly what you mean by "I can't save a binary file using
'bytearray(')". Do you get a traceback, if so, copy it in your message,
along with actual code that produces your problem (preferably simplified,
but not too far).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131216/8b7f9c31/attachment.html>

More information about the Python-list mailing list