problems with shelve(), collections.defaultdict, self

7stud 7stud at
Sat Feb 11 04:30:47 CET 2012

On Feb 10, 7:52 pm, 7stud <7s... at> wrote:

I don't know if this helps, but I notice when I initially do this:'data22')

the file is saved as 'data22.db'.   But on subsequent calls to, if I use the file name 'data22.db', I get a different


**** defaultdict(<class 'int'>, {'Joe': 30})
Traceback (most recent call last):
  File "", line 95, in <module>
  File "", line 86, in load
    my_shelve ='data22.db')
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/", line 232, in open
    return DbfilenameShelf(filename, flag, protocol, writeback)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/", line 216, in __init__
    Shelf.__init__(self,, flag), protocol,
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/dbm/", line 83, in open
    raise error[0]("db type could not be determined")
dbm.error: db type could not be determined

The code that produced that error:

import collections as c
import shelve

class Dog(c.defaultdict):
    def __init__(self):
        super().__init__(int, Joe=30)
        print('****', self)

    def save(self):
        my_shelve ='data22')
        my_shelve['dd'] = self

    def load(self):
        my_shelve ='data22.db')
        data = my_shelve['dd']


d = Dog()

I'm using python 3.2.2.

More information about the Python-list mailing list