Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > shelve problem

Reply
Thread Tools

shelve problem

 
 
Michael Mulcahy
Guest
Posts: n/a
 
      03-02-2004
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with shelve bluesmanu@gmail.com Python 1 11-06-2008 06:07 PM
Problem with shelve/gdbm Douglas Applegate Python 0 10-19-2007 08:58 PM
hi,everyone. a problem with shelve Module softwindow Python 4 05-26-2006 12:00 PM
shelve keeping old (unused) data around? AK Python 2 09-29-2003 09:43 PM
Serious problem with Shelve Rami A. Kishek Python 6 08-19-2003 10:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57