<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Dec 16, 2013 at 2:19 PM, Djoser <span dir="ltr"><<a href="mailto:pedrovg000@gmail.com" target="_blank">pedrovg000@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi all,<br>
<br>
I am new to this forum and also to Python, but I'm trying hard to understand it  better.<br>
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.<br>


<br>
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(') </blockquote>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


How can I do that?<br></blockquote><div><br></div><div><br></div><div>What you probably want is to use the struct module:</div><div><a href="http://docs.python.org/3/library/struct.html">http://docs.python.org/3/library/struct.html</a> </div>

<div><br></div><div>You probably also want the open method and file objects:</div><div><a href="http://docs.python.org/3/library/functions.html#open">http://docs.python.org/3/library/functions.html#open</a><br></div><div>

<br></div><div>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).</div>

</div></div></div>