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


Groups > comp.lang.python > #98768

Re: Problems using struct pack/unpack in files, and reading them.

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Problems using struct pack/unpack in files, and reading them.
Date Fri, 13 Nov 2015 14:05:04 -0700
Lines 13
Message-ID <mailman.307.1447448752.16136.python-list@python.org> (permalink)
References <20151113192045.GA9913@z-sverige.nu> <CALwzidnL1N8efgJfM-EKTgqzmDjg2QwcZVVmDXJB2_QGyFnExA@mail.gmail.com> <20151113201510.GA10107@z-sverige.nu>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de lGPig08DWngMM9J0qHBYMwBJN4H6Du5la3R/s62wfw9A==
Return-Path <ian.g.kelly@gmail.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; 'received:209.85.223': 0.03; 'bytes.': 0.07; 'correct.': 0.07; 'tmp': 0.07; 'subject:files': 0.09; 'subject:using': 0.09; 'unpack': 0.09; 'unpacking': 0.09; 'assume': 0.11; 'suggest': 0.15; 'argument': 0.15; 'received:209.85.223.173': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Problems': 0.16; 'unpack.': 0.16; 'wrote:': 0.16; 'string': 0.17; 'bytes': 0.18; '2015': 0.20; 'arguments': 0.22; 'function,': 0.22; 'passing': 0.23; 'header:In- Reply-To:1': 0.24; 'error': 0.27; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; '13,': 0.29; 'read,': 0.29; 'print': 0.30; 'subject:/': 0.30; 'that.': 0.30; 'strongly': 0.30; 'says': 0.32; 'run': 0.33; 'worked': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'nov': 0.35; 'should': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'doing': 0.38; 'received:209': 0.38; 'log': 0.38; 'does': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'skip:u 10': 0.61; 'kent': 0.84; 'subject:pack': 0.84; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=ZDE82gq2kRjqtNxuleGnhgLPhgSyuxGwIBEWkwr5w1Y=; b=WvaHFX99Eeby4/uxtv/Z0Hr3ExtuEgUHGy0Zx0/N33RfiXDUQ2KCWwsOych3YXxZCs 1WJy0e7Tt3b0F+ZIVqnWWspUzrzolPvzZEar9O9z4owlQkTMFgoPBYnkIRW66ASW+KKt sn+tZaOWIHVLLvQ6O1i8867bUdloK74/TcchhbIjEnzjsKgPWwS3WUyA06fNyKYPphmM P6rIVN29J/V5DIcIT/7skqiZ37Bb+ydPdwmTYIYTDVoW2Ok3fHbAa/lpT+JqChD116Og 16/6qoWgJY5cBxdbDct5dKqoBgYIWezafU6QM6l140+VT4QIBVjiOxwJkQ0URPk/qCXU L1pA==
X-Received by 10.107.164.154 with SMTP id d26mr22786527ioj.111.1447448743848; Fri, 13 Nov 2015 13:05:43 -0800 (PST)
In-Reply-To <20151113201510.GA10107@z-sverige.nu>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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>
Xref csiph.com comp.lang.python:98768

Show key headers only | View raw


On Fri, Nov 13, 2015 at 1:15 PM, kent nyberg <kent@z-sverige.nu> wrote:
> What bothers me, is the error that says
> unpack requires a string argument of 4 bytes.
> Im thinking in the line of arguments? Does unpack look at the 4 bytes it has read, and tell for some
> reason say that unpacking needs an argument of 4 bytes?  I know that I can set the arguments
> for unpack. I have done that.  It is: unpack('>HH', tmp).
> So either '>HH' or tmp is wrong. Since '>HH' worked for the first run of the function, I assume its correct.
> And as far as I know,   doing .read()[RegisterAX:RegisterAX:+4]  should read the following
> 4 bytes.

By the way, I would strongly suggest that you print or log the value
of repr(tmp) so that you *know* what you're passing to unpack rather
than having to speculate about it.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-13 14:05 -0700

csiph-web