473,569 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\li b\shelve.py", line 118, in __getitem__
f = StringIO(self.d ict[key])
File "E:\Python23\li b\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 3510
jo*******@gmx.n et 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\li b\shelve.py", line 118, in __getitem__
f = StringIO(self.d ict[key])
File "E:\Python23\li b\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
4729
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 class I define. It works perfectly on an old machine (PII-400) running Python 2.2.1 under RedHat Linux 8.0. When I try to run it under Python for...
1
6715
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 = shelve.open('shelvedata.txt',writeback=True) >>> d= >>> d=d >>> print d {'a': , 'b': } >>> d=2 >>> print d {'a': , 'b': }
0
2455
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 __init__and defined a __del__ method to clean up resources. I then discovered asimilar problem in the shelve module. This led me to two...
0
1095
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 change. I expected the db.txt file to get smaller. def delete(): s = shelve.open('db.txt') del s s.close()
8
1561
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 minimum gesture towards durability of updates. But say that s is a shelve object. If I say s = value there is no way apparent from the shelve...
3
7764
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 import shelve class XX: def __init__(self): self._data = shelve.open("/tmp/myfile")
6
4426
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 error, anydbm.error, shelve.open.anydb.error, etc. but can't find it. Things
13
6474
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
1640
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 ported my Python program today to the PC, it quickly crashed. Everything seems to work except for shelve. Using the latest version of Python (2.5.1),...
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.