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


Groups > comp.lang.python > #27890

Re: issue with struct.unpack

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; '"""': 0.05; 'subject:skip:s 10': 0.05; 'bytes.': 0.07; 'character,': 0.07; 'interpreted': 0.07; 'width': 0.07; 'python': 0.09; 'integer,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'truncated': 0.09; 'unpack': 0.09; 'aug': 0.13; 'resulting': 0.13; 'sat,': 0.15; '"...': 0.16; '"s"': 0.16; 'file).': 0.16; 'format?': 0.16; 'packing,': 0.16; 'padded': 0.16; 'readable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'retrieving': 0.16; 'subject:issue': 0.16; 'unload': 0.16; 'string': 0.17; 'bytes': 0.17; 'specify': 0.17; 'string,': 0.17; 'module': 0.19; 'appropriate': 0.20; 'variable': 0.20; 'trying': 0.21; 'struct': 0.22; 'errors': 0.23; 'specified': 0.23; 'values': 0.26; 'first,': 0.27; 'header:X-Complaints-To:1': 0.28; 'relies': 0.29; 'types.': 0.29; 'case,': 0.29; 'this.': 0.29; 'field,': 0.30; 'checked': 0.30; 'asked': 0.33; 'null': 0.33; 'url:home': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'received:org': 0.36; 'but': 0.36; 'data.': 0.36; 'subject:with': 0.36; 'charset:us-ascii': 0.36; 'two': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'short': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'your': 0.60; "you've": 0.61; 'repeat': 0.62; 'skip:n 10': 0.63; 'fit.': 0.65; 'serial': 0.66; 'special': 0.73; '(while': 0.84; 'pardon': 0.84; 'single,': 0.84; 'dennis': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: issue with struct.unpack
Date Sat, 25 Aug 2012 19:31:03 -0400
Organization > Bestiaria Support Staff <
References <2cc8b390-0b7a-4a0f-ac88-113daf65eba5@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-76-249-19-241.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 3.3/32.846
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3818.1345938381.4697.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1345938381 news.xs4all.nl 6894 [2001:888:2000:d::a6]:53256
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:27890

Show key headers only | View raw


On Sat, 25 Aug 2012 11:34:39 -0700 (PDT), 9bizy
<a.m.akingbulu-11@student.lboro.ac.uk> declaimed the following in
gmane.comp.python.general:

> I am trying to unpack values from sensor data I am retrieving through a serial cable, but I get errors while using struct.unpack, how can I use struct.unpack to unload the data in a readable format?
> 
> I checked the python documentation for struct and I can seen to find any argument for this.
>
	Pardon "... I can seen to find..."?
 
> I have data = struct.unpack('char',data) but I still get errors

	No surprise... You've asked for a single-character, a short integer,
and two unknown field types.

	What about

"""
s char[] string 
"""

and

"""
For the "s" format character, the count is interpreted as the size of
the string, not a repeat count like for the other format characters; for
example, '10s' means a single 10-byte string, while '10c' means 10
characters. For packing, the string is truncated or padded with null
bytes as appropriate to make it fit. For unpacking, the resulting string
always has exactly the specified number of bytes. As a special case,
'0s' means a single, empty string (while '0c' means 0 characters). 
"""

(both from the 2.5 help file).

The struct module relies upon the user knowing the format of the data.
If your problem is that you have some null-terminated string data in a
variable width field, you will have to locate the position of the null
FIRST, and specify the appropriate "count" for the s format.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


Thread

issue with struct.unpack 9bizy <a.m.akingbulu-11@student.lboro.ac.uk> - 2012-08-25 11:34 -0700
  Re: issue with struct.unpack Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-25 20:12 +0100
  Re: issue with struct.unpack MRAB <python@mrabarnett.plus.com> - 2012-08-25 20:16 +0100
    Re: issue with struct.unpack 9bizy <a.m.akingbulu-11@student.lboro.ac.uk> - 2012-08-28 15:35 -0700
      Re: issue with struct.unpack MRAB <python@mrabarnett.plus.com> - 2012-08-28 23:53 +0100
      Re: issue with struct.unpack Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-28 22:40 -0400
    Re: issue with struct.unpack 9bizy <a.m.akingbulu-11@student.lboro.ac.uk> - 2012-08-28 15:35 -0700
  Re: issue with struct.unpack Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-25 19:31 -0400
    Re: issue with struct.unpack Alexander Blinne <news@blinne.net> - 2012-08-26 14:53 +0200
  Re: issue with struct.unpack MRAB <python@mrabarnett.plus.com> - 2012-08-28 23:49 +0100
    Re: issue with struct.unpack 9bizy <a.m.akingbulu-11@student.lboro.ac.uk> - 2012-08-28 16:01 -0700
    Re: issue with struct.unpack MRAB <python@mrabarnett.plus.com> - 2012-08-29 00:36 +0100
      Re: issue with struct.unpack 9bizy <a.m.akingbulu-11@student.lboro.ac.uk> - 2012-08-28 16:55 -0700
      Re: issue with struct.unpack 9bizy <a.m.akingbulu-11@student.lboro.ac.uk> - 2012-08-28 16:55 -0700
  Re: issue with struct.unpack Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-28 22:31 -0400

csiph-web