By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

Integer keys in shelve

P: n/a
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:
d[1]

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

Mar 14 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
jo*******@gmx.net wrote:
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\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/li...le-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>

Mar 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.