473,386 Members | 1,821 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,386 software developers and data experts.

shelve problem

Hi All,

Problem: Shelve module doesn't like me

OS: Win2000
version: 2.3.3

Here is simple reproduction code and the error that occurs:

import shelve, anydbm
try:
test = shelve.open('hello', 'r') # file hello does not exist
except:
pass # this is called as hello does not exist

Exception exceptions.AttributeError: "DbfilenameShelf instance has no
attribute 'writeback'" in

Stack:
'__main__', line 7: pass
'shelve'.__del__(), line 148: self.close()
'shelve'.close(), line 140: self.sync() 'shelve'.sync, line 151: if self.writeback and self.cache:


Forgive me if this query is obvious but I have searched mailing lists
and google but could not resolve the issue.

Speculative Analysis:

shelve.open calls the DbfilenameShelf constructor passing the filename
"hello".

The DbfilenameShelf constructor does the following:

def __init__(self, filename, flag='c', protocol=None,
writeback=False, binary=None):
import anydbm
Shelf.__init__(self, anydbm.open(filename, flag), protocol,
writeback, binary)

The function anydbm.open throws an exception because:
1. the filename does not exist
2. the flag does not not contain a 'c' or an 'n'
(See anydbm.py line 77)

As the file "hello" does not exist the exception is thrown and caught
in my code.

I presume that python constructs the DbfilenameShelf object but does
not construct the parent shelf object because of that exception.

Then when python is cleaning up it destructs the DbfilenameShelf
object which I presume calls the destructor of the parent shelf
object. As the shelf object was not created due to initial exception,
python could not see the attributes and hence the Attribute Error
exception.

Comments Anyone?

Any questions please do not hesitate to contact me.

Michael.
Jul 18 '05 #1
0 1346

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...
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: ex laguna | last post by:
Hi, I have ran into a problem with py2exe 0.5.0 and shelve in python 2.3.3. The script works fine standalone, but not with py2exe. Does anyone have a solution of workaround for this? Thanks...
0
by: Ray O | last post by:
I have read a number of threads relating to problems with shelve, but I couldn't find one directly related my experience, so I would appreciate some advice. The closest one ended with a...
5
by: Philippe C. Martin | last post by:
Hi, I just installed (compiled) Python 2.4.2 under Suse 10. The following code generates a seg error: import shelve print shelve.open ('test') I assume this has to do with the db behind...
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...
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...
1
by: Matthew Schibler | last post by:
I'm a newbie to Python, with some experience using perl (where I used nested arrays and hashes extensively). I am building a script in python for a MUD I play, and I want to use the shelve module...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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,...
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.