473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Integer keys in shelve

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
1 3492
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rami A. Kishek | last post by:
Hi - this mysterious behavior with shelve is just about to kill me. I hope someone here can shed some light. First of all, I have this piece of code which uses shelve to save instances of some...
1
by: Kris Caselden | last post by:
Python's docs say that Shelve uses Pickle to serialize its data. However, I've noticed that Pickle can maintain internal links, while Shelve cannot. For instance: >>> d =...
0
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside...
0
by: Olaf Meding | last post by:
Why does a shelve file never get smaller? I noticed that the shelve file (db.txt, see below) does not change (get smaller) when deleting a key. The key is deleted but the file size does not...
8
by: Paul Rubin | last post by:
Shelve uses dbm and pickle to make a persistent object store. The "db" in "dbm" stands for "database" and while I didn't expect full ACID capability, I'd have thought there'd be at least some...
3
by: Michele Petrazzo | last post by:
Hi, I'm trying a script on a debian 3.1 that has problems on shelve library. The same script work well on a fedora 2 and I don't know why it create this problem on debian: #extract from my code...
6
by: aomighty | last post by:
I wanted to write the following code: import shelve try: db = shelve.open(file, "r") except SomeError: print "Oh no, db not found" Only, I'm not sure what SomeError should be. I tried...
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
5
by: gluckj | last post by:
Hi, I'm not a Win ME fan myself (I'm a Mac user), but I'm here in Thailand developing software for special-needs kids, and the test PC in my home office is a Win ME machine (sigh). So when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.