Shelve and classes

j vickroy jvickroy at sec.noaa.gov
Wed Aug 9 17:05:54 EDT 2000


Hello Curtis,

I'm running Python 1.5.2 and here is a sample session:

>>>
>>> import shelve
>>> writer = shelve .open ('my_db')
>>> writer ['1'] = 'a'
>>> writer .close()
>>> reader = shelve .open ('my_db')
>>> reader ['1']
'a'
>>> reader .close()
>>>

Notice, I did not specify a filetype suffix for the name of the dbm file.
Try that; I doubt the problem is with the class you were trying to archive.

Curtis Jensen wrote:

> I have several data classes (only contain array data).  I want to use
> shelve to save this data to a database.  I tried and this is what I got:
>
> >>> import shelve
> >>> d = shelve.open('tmp.db')
> >>> d['nodes'] = nodes
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
>   File "/usr/local/Python/lib/python1.5/shelve.py", line 71, in
> __setitem__
>     self.dict[key] = f.getvalue()
> dbm.error: Cannot add item to database
> >>>
>
> nodes was already declared as an instance of one of my classes.  What am
> I doing wrong?  Thanks.
>
> --
> Curtis Jensen
> cjensen at bioeng.ucsd.edu
> http://www-bioeng.ucsd.edu/~cjensen/
> FAX (425) 740-1451




More information about the Python-list mailing list