Integer keys in shelve

J

josegomez

Hi!
I want to use shelve to store lists which are indexed by an integer
key. The keys are not concurrent or anything, they are just defined as
integer values. However, shelve complains that I cannot have integer
keys. Here's the error:
Traceback (most recent call last):
File "<input>", line 1, in ?
File "E:\Python23\lib\shelve.py", line 118, in __getitem__
f = StringIO(self.dict[key])
File "E:\Python23\lib\bsddb\__init__.py", line 116, in __getitem__
return self.db[key]
TypeError: Integer keys only allowed for Recno and Queue DB's

I understand that Recno is part of the bsddb3, but I don't know how to
instruct shelve to use the Recno back-end.

The other option is to str() the integer key, but I'd rather use an
integer key, and avoid all the extra clutter.

Did I miss something?

Ta
Jose
 
F

Fredrik Lundh

I want to use shelve to store lists which are indexed by an integer
key. The keys are not concurrent or anything, they are just defined as
integer values. However, shelve complains that I cannot have integer
keys. Here's the error:
Traceback (most recent call last):
File "<input>", line 1, in ?
File "E:\Python23\lib\shelve.py", line 118, in __getitem__
f = StringIO(self.dict[key])
File "E:\Python23\lib\bsddb\__init__.py", line 116, in __getitem__
return self.db[key]
TypeError: Integer keys only allowed for Recno and Queue DB's

I understand that Recno is part of the bsddb3, but I don't know how to
instruct shelve to use the Recno back-end.

The other option is to str() the integer key, but I'd rather use an
integer key, and avoid all the extra clutter.

Did I miss something?

the documentation ?

http://www.python.org/doc/current/lib/module-shelve.html

A "shelf" is a persistent, dictionary-like object. The difference
with "dbm" databases is that the values (not the keys!) in a
shelf can be essentially arbitrary Python objects -- anything
that the pickle module can handle. This includes most class
instances, recursive data types, and objects containing lots
of shared sub-objects. The keys are ordinary strings.

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top