Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62109
| References | <3dcea919-82ad-4e0a-a00a-fa04ba39b1dd@googlegroups.com> |
|---|---|
| From | Chris Kaynor <ckaynor@zindagigames.com> |
| Date | 2013-12-16 14:28 -0800 |
| Subject | Re: [newbie] Saving binaries in a specific way |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4238.1387232927.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On Mon, Dec 16, 2013 at 2:19 PM, Djoser <pedrovg000@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:
http://docs.python.org/3/library/struct.html
You probably also want the open method and file objects:
http://docs.python.org/3/library/functions.html#open
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).
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[newbie] Saving binaries in a specific way Djoser <pedrovg000@gmail.com> - 2013-12-16 14:19 -0800
Re: [newbie] Saving binaries in a specific way Chris Kaynor <ckaynor@zindagigames.com> - 2013-12-16 14:28 -0800
Re: [newbie] Saving binaries in a specific way Djoser <pedrovg000@gmail.com> - 2013-12-16 14:35 -0800
Re: [newbie] Saving binaries in a specific way Tim Chase <python.list@tim.thechases.com> - 2013-12-16 16:48 -0600
Re: [newbie] Saving binaries in a specific way Djoser <pedrovg000@gmail.com> - 2013-12-16 15:30 -0800
Re: [newbie] Saving binaries in a specific way rusi <rustompmody@gmail.com> - 2013-12-16 17:01 -0800
Re: [newbie] Saving binaries in a specific way Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-12-17 11:21 +0000
Re: [newbie] Saving binaries in a specific way Djoser <pedrovg000@gmail.com> - 2013-12-17 10:54 -0800
csiph-web