Shelve and Object Size

Johan Ur Riise riise at bgnett.no
Sun Aug 13 22:53:43 EDT 2000


Curtis Jensen <cjensen at bioeng.ucsd.edu> writes:

> Is there a limit on the size of an object that shelve can handle?  For
> example:
> 
> >>> import shelve
> >>> from Numeric import *
> >>> writer = shelve.open ( 'my_db' )
> >>> writer['2'] = zeros([2])
> >>> writer['big'] = zeros([1000000])
> 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
> 
> I need to but some rather large Python objects into a database.  I
> thought shelve would be the easiest way.  How should I do this?  Can I
> make shelve work, or should I use something different?  Thanks.
> 

Check with the file command in the os what type of dbm-system
is used, after you create a shelve. I once had to do something
like this:

import gdbm
db = gdbm.open('myfile','c')
db.close()

then, in subsequent sessions:

import shelve
db=shelve.open('myfile')
[..operations on db..]

>From the gdbm manpage:

       NOTICE: The size in gdbm is not  restricted  like  dbm  or
       ndbm.  Your data can be as large as you want.


-- 
Johan



More information about the Python-list mailing list