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


Groups > comp.lang.python > #59147 > unrolled thread

Reading c struct via python

Started by"Lakshmipathi.G" <lakshmipathi.g@gmail.com>
First post2013-11-12 09:44 +0530
Last post2013-11-12 09:44 +0530
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#59147 — Reading c struct via python

From"Lakshmipathi.G" <lakshmipathi.g@gmail.com>
Date2013-11-12 09:44 +0530
SubjectReading c struct via python
Message-ID<mailman.2426.1384229720.18130.python-list@python.org>

[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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web