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


Groups > comp.lang.python > #59322

Re: Reading c struct via python

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!newsfeeder.ewetel.de!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <lakshmipathi.g@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; 'output': 0.05; 'string.': 0.05; 'binary': 0.07; 'string': 0.09; 'foss': 0.09; 'inserted': 0.09; 'key.': 0.09; 'parsing': 0.09; 'terminated': 0.09; 'cc:addr :python-list': 0.11; '"o"': 0.16; 'definition.': 0.16; 'dig': 0.16; 'here.\xa0': 0.16; 'storing': 0.16; 'subject:Reading': 0.16; 'unpack': 0.16; 'subject:python': 0.16; 'fix': 0.17; 'module': 0.19; 'cc:addr:python.org': 0.22; 'sorry,': 0.24; 'url:home': 0.24; 'cheers,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '&gt;': 0.26; 'header:In-Reply-To:1': 0.27; 'record': 0.27; 'testing': 0.29; 'rest': 0.29; '----': 0.29; 'character': 0.29; "doesn't": 0.30; 'forgot': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'posting': 0.31; 'struct': 0.31; 'url:python': 0.33; 'actual': 0.34; 'info': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'format.': 0.36; 'url:listinfo': 0.36; 'doing': 0.36; "didn't": 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'step': 0.37; 'skip:& 10': 0.38; 'handle': 0.38; 'expect': 0.39; 'url:mail': 0.40; 'length': 0.61; 'first': 0.61; 'skip:n 10': 0.64; 'url:co': 0.67; 'c-type': 0.84; 'subject:via': 0.84; 'directly.': 0.95
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 :cc:content-type; bh=QoryKzzDz0gZ0DxBf37RdH85/1nC66NbDfdnWl2WL9Q=; b=L8Iz80TWJlsZSGQ30JBpVVEuIhBhVT+mJGtqogkTnU2I4cdTuU0YgnR8ADdSGVexM+ LJdebF1AgHkDlvB66YV0qDaw69fC6IW5cI5+AsL64+J9e5mGFUUTdsAQf+l02b9dCRWt ZxZ8PLmS43CzfRg24LGfnksy/iMcbkeUAmooupZLQ9Sd+GYmTzFcs5KHfv0OuwLysGXs nJ/sqRJ8TJdu+NU6MVXnzsIpZHczCUZEf7Mt57ep0Lw1mN3AWWDijrfWXZ6n5Zo8eTKg CJDY1oSRfN71ek2GTmiACFNrPKdglTPJMrDM5/p5spf3OJtAqOSnVB1m4zh/4EW93+Mw lUKA==
X-Received by 10.180.11.166 with SMTP id r6mr21842162wib.9.1384365563587; Wed, 13 Nov 2013 09:59:23 -0800 (PST)
MIME-Version 1.0
In-Reply-To <69l589d5ilgqp6phcj5jn6s9c5220fbbpa@4ax.com>
References <CAKuJGC_-i66xtk0aitHKpBQ74ufDKzRn7vXEBjiar+hSGTFZfg@mail.gmail.com> <69l589d5ilgqp6phcj5jn6s9c5220fbbpa@4ax.com>
From "Lakshmipathi.G" <lakshmipathi.g@gmail.com>
Date Wed, 13 Nov 2013 23:29:03 +0530
Subject Re: Reading c struct via python
To Dennis Lee Bieber <wlfraed@ix.netcom.com>
Content-Type multipart/alternative; boundary=001a11c248f0a83af504eb12b937
Cc python-list@python.org
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.2543.1384365571.18130.python-list@python.org> (permalink)
Lines 100
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1384365571 news.xs4all.nl 15931 [2001:888:2000:d::a6]:46178
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:59322

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

> Looks like your "e"... Is that the key field?

Yes, you are right 'e' is the key. And rest of them are data.

>AND the order of the items is "o" before "i"
>-- that doesn't seem to match your C struct definition.

Sorry, I was testing the bdb and while doing that I noticed,
c-struct order is not same as inserted bdb record . But forgot to
fix the struct order before posting it here.

(And also I didn't expect someone will dig this deeper on the binary
string output :p . Thanks for your effort! )


>"s" format in which you precode the length of the string in the
>format ("10s" is a 10 character string), and "p" format in which the first
>byte of the string is the length (0..255) of the rest of the string. The
>struct module doesn't handle C-type null terminated strings directly.

I think we can use 'p' format. (Thus storing the string-length before
actual
string content). That should help us unpack easily.

Thanks  Dennis Lee Bieber, for the detailed info and step by step parsing
of the output. It really helped.



--
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>     wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
----
Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in

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


Thread

Re: Reading c struct via python "Lakshmipathi.G" <lakshmipathi.g@gmail.com> - 2013-11-13 23:29 +0530

csiph-web