Integer keys in shelve

josegomez at josegomez at
Tue Mar 14 10:17:24 CET 2006

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:
>>> d[1]
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "E:\Python23\lib\", line 118, in __getitem__
    f = StringIO(self.dict[key])
  File "E:\Python23\lib\bsddb\", 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?


More information about the Python-list mailing list