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


Groups > comp.lang.python > #59147

Reading c struct via python

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'none,': 0.07; '-we': 0.09; 'cursor': 0.09; 'foss': 0.09; 'python': 0.11; '*s;': 0.16; 'etc?': 0.16; 'recently.': 0.16; 'skip:" 100': 0.16; 'storing': 0.16; 'subject:Reading': 0.16; 'unsigned': 0.16; 'subject:python': 0.16; 'module': 0.19; 'help.': 0.21; 'import': 0.22; 'python?': 0.22; 'print': 0.22; 'char': 0.24; 'integer': 0.24; 'cheers,': 0.24; '---': 0.24; 'question': 0.24; '----': 0.29; 'skip:( 40': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'code': 0.31; 'skip:( 50': 0.31; 'struct': 0.31; 'says': 0.33; 'url:python': 0.33; 'proceed': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.35; 'google': 0.35; 'entry': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'searching': 0.37; 'url:library': 0.38; 'writes': 0.38; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'further': 0.61; 'back': 0.62; 'url:co': 0.67; 'subject:via': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=VesFba/PqzNTafmNORaYC7JEq/cwmsXzXnbz6Rny/j8=; b=SgVlqCgjf1DR1/K+G3EDzr4u3eI81wp7Gui4wuOLHDtC5dQc9D2JLjUVd6ZCfNmRtV rPKo2sMrtSDahnpwUnWf18pDanoU737A1snsXmckSOXKARNow8dqiPnrp1TulynNqKHA KekBCltEmMIV7Nz59WvgBPnrc8sbzWtUD84AGZrlX3B4ulFHBthdJYgjKf3BCbJlDs/3 8P0D6sYHdoSmy5vVkRo+Ko6ubr7RlwK89QaB9PB7+On5V1M2ny4kwZbcB+aQq5nSQtvQ Nkj3fLrigp+W1apInXlwn6UY+IjBkufHGbSys87gHE9UQ2SUvoUo21SkoAApAMlSR0D9 TQqQ==
X-Received by 10.180.198.198 with SMTP id je6mr14346455wic.7.1384229713021; Mon, 11 Nov 2013 20:15:13 -0800 (PST)
MIME-Version 1.0
From "Lakshmipathi.G" <lakshmipathi.g@gmail.com>
Date Tue, 12 Nov 2013 09:44:51 +0530
Subject Reading c struct via python
To python-list@python.org
Content-Type multipart/alternative; boundary=047d7b624dd8551ab004eaf318fe
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.2426.1384229720.18130.python-list@python.org> (permalink)
Lines 99
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1384229720 news.xs4all.nl 15998 [2001:888:2000:d::a6]:38202
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:59147

Show key headers only | View raw


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

Hi -
We have C code which writes following struct into berkeley db ("my_db.db").

struct my_info {
    unsigned long int i, e;
    int o;
    char *f;
    char *s;
};

How to read this via Python? Google search gave this code
---
$ cat pybsd2.py
from bsddb import db
fruitDB = db.DB()
fruitDB.open('my_db.db', None, db.DB_BTREE, db.DB_DIRTY_READ)
cursor = fruitDB.cursor()
rec = cursor.first()
while rec:
    print rec
    rec = cursor.next()
fruitDB.close()
---

While storing an entry (o=>500,f=>/home/laks/abcde,s=>OSr,i=>4668368
,e=>10000) and reading it back i get

$ python pybsd2.py
("\x10'\x00\x00\x00\x00\x00\x00",
"\xf4\x01\x00\x00\xd0;G\x00\x00\x00\x00\x00\x10'\x00\x00\x00\x00\x00\x00/home/laks/abcde\x00OSr\x00")

And this http://docs.python.org/2/library/bsddb.html says bdb module is
removed  recently.

Further Searching provides modules like cpickle,ctypes,struct - not sure
which is the right approach/way to proceed.
Should we proceed with bdb module and find out how to retrive integer from
db or use others like ctypes/(c)pickle/struct etc?

Thanks for any help.

Ps : If this question already answered and discussed often, please redirect
me to that thread.

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

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


Thread

Reading c struct via python "Lakshmipathi.G" <lakshmipathi.g@gmail.com> - 2013-11-12 09:44 +0530

csiph-web