Best way to acces shelves from embedded python

Craig Rendon c.rendon at attbi.com
Mon Nov 11 17:44:05 EST 2002


Dear Python  People,

Question:

My question is:  what is the best way to access shelves from embedded
python?

What I've done so far:

I am trying to write a serial driver daemon that loads a simple database of
comm port parms from a Python shelve.  Using the "simple strings" strategy,
I get an ImportError.  The error (see traceback, .c and .py modules below)
is due to an undefined symbol in struct.so.  If I use the "calling Python
Objects in modules" strategy (e.g. PyImport_ImportModule() and
PyEval_CallObject()), I get a core dump without a traceback.

Thanks, Craig Rendon (c.rendon at attbi.com)

TraceBack:

File <string> in line1
File /opt/nmcs/src/Driver/getshelve.py line1
    import shelve
File /usr/local/lib/python2.2/shelve.py line 36
    from pickle import Pickle, Unpickle
File /usr/local/lib/python2.2/pickle.py line 32
    import struct
ImportError: /usr/local/lib/python2.2/lib-dynload/struct.so: undefined
symbol: PyString_Type


driverd.c module:

#include Python.h
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('/opt/nmcs/src/Driver')");    #path of
getshelve.py
PyRun_SimpleString("getshelve.getshelve('/opt/nmcs/py/comm.shv')");  #print
out dict


getshelve.py module:

#just print out the db when the func is run from the embedded code
import shelve
def getshelve(file):
    db=open.shelve(file)
    print "getshelve: db", db['comm']  #my db is a dict that is a value for
the 'comm'





More information about the Python-list mailing list