Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62109

Re: [newbie] Saving binaries in a specific way

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ckaynor@zindagigames.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; '16,': 0.03; 'subject:: [': 0.04; 'that?': 0.05; 'binary': 0.07; 'converted': 0.09; 'objects:': 0.09; 'python': 0.11; '&quot;i': 0.16; 'matlab': 0.16; 'using,': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'trying': 0.19; 'file,': 0.19; 'subject:] ': 0.20; 'email addr:gmail.com&gt;': 0.22; 'to:name:python- list@python.org': 0.22; 'mon,': 0.24; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'converting': 0.30; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'along': 0.30; "i'm": 0.30; 'code': 0.31; 'lines': 0.31; "skip:' 10": 0.31; 'produces': 0.31; 'struct': 0.31; 'file': 0.32; 'probably': 0.32; 'open': 0.33; 'url:python': 0.33; 'actual': 0.34; 'problem': 0.35; "can't": 0.35; 'received:209.85': 0.35; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'method': 0.36; 'url:org': 0.36; 'so,': 0.37; 'too': 0.37; 'received:209': 0.37; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'forum': 0.61; 'new': 0.61; 'url:3': 0.61; 'first': 0.61; 'save': 0.62; 'information': 0.63; '2013': 0.98
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=6wAoB5hAOvT6/z1ZKyU+algtIXWc9bIPKIlsO1IGii8=; b=OEgQp1a+ggBpU4n1S4GB+yO7VeRkQmKy+d2CepuZeeZ4ajvcqHPg0kKj7aSGwZSyXb xd/7bmCKtP3weF1tR8DXOSMEaFJmMfSNB/PFh8k/WNIMBLVPnQViDoHBRmWHV9K+83Ei 29ciaqZBTlSmynDSxnABlPylfd3qPcxFQ4i5C7Q5X27SPwvgYBVAyi4SuXY8fRhfp+XH /pbgecd9kPTK1Cdn82DlCl9YF/adws6KVMzMsZjaLbQH0NCFZIF4KcEIWHvheo30yBwJ zBnTWZYQp9kxG66WTxYM0U3A7uCcuUzdWNtcvWVjRJjBrFX4Bp7vb0oXtBjrFKjTlf30 ZRyQ==
X-Gm-Message-State ALoCoQltBYAVt+znDlCXB0bHRqstCPvW1+8GxzssteHQkjeCBWJulmhoOVuHRTS/2XmJvGOB9ylh
X-Received by 10.182.158.71 with SMTP id ws7mr13745174obb.6.1387232919085; Mon, 16 Dec 2013 14:28:39 -0800 (PST)
MIME-Version 1.0
In-Reply-To <3dcea919-82ad-4e0a-a00a-fa04ba39b1dd@googlegroups.com>
References <3dcea919-82ad-4e0a-a00a-fa04ba39b1dd@googlegroups.com>
From Chris Kaynor <ckaynor@zindagigames.com>
Date Mon, 16 Dec 2013 14:28:18 -0800
Subject Re: [newbie] Saving binaries in a specific way
To "python-list@python.org" <python-list@python.org>
Content-Type multipart/alternative; boundary=089e01494a165cfe5604edae558b
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4238.1387232927.18130.python-list@python.org> (permalink)
Lines 88
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387232927 news.xs4all.nl 2873 [2001:888:2000:d::a6]:56178
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62109

Show key headers only | View raw


[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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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