Shelves: Alternatives?

David dlashar at sprynet.com
Fri Nov 8 11:09:49 EST 2002


A few days ago, I posted a question about a quirky error in which the
loading of a shelve file was suddenly raising an error (see below).  The
problem, it seems, is that when the object being stored reaches a certain
size, the shelve module can no longer handle it.  (I'm running Python 2.2.1
on Win2000; the break point seems to be somewhere around 100KB.)  I can get
around this problem using the pickle module.  But, still a Python newbie, I
was wondering if there's an alternative to the standard shelve module that I
could/should try?  Thanks in advance.

    David

Original Posting:

Hello.  I am getting some behavior with shelves that I can't figure out.  As
shown below, I have a data file that yields an error when the keys() method
is initially invoked.  If, however, I invoke the keys() method after
checking for the existence of the expected key (w/ the has_key() method),
the keys() method "suddenly" works.  Any insights/suggestions would be
appreciated.  Thanks,

    David

>>> sh = shelve.open('c:\\jdl_files\\sport.data')
>>> sh.keys()
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "shelve.py", line 56, in keys
    return self.dict.keys()
error: (22, 'Invalid argument')
>>> sh.dict.has_key('baseball')
1
>>> sh.keys()
['baseball']
>>> sh.close()








More information about the Python-list mailing list