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

shelve problem

P: n/a
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
test ='hello', 'r') # file hello does not exist
pass # this is called as hello does not exist

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

'__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: calls the DbfilenameShelf constructor passing the filename

The DbfilenameShelf constructor does the following:

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

The function throws an exception because:
1. the filename does not exist
2. the flag does not not contain a 'c' or an 'n'
(See 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

Comments Anyone?

Any questions please do not hesitate to contact me.

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.