[EMAIL PROTECTED] wrote: > why does the following error occur? I don't know; I've never used the shelve module. Let's see what as two utter n00bz we can find out. Let's check out where it clagged: lib\anydbm.py, line 80, in open ...
Hmm, reading backwards a little, looks like it called whichdb.whichdb to nut out what sort of database it was, and whichdb reported back that it was an existing file, of unknown type. Flicking through whichdb.py confirms this. Let's see if we can reproduce that: === step 1: file doesn't exist === C:\junk>c:\python23\python Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import shelve >>> df = shelve.open('mydata.dat', 'c') >>> ^Z C:\junk>dir mydata.dat [snip] 26/02/2005 08:40p 24,576 mydata.dat === looks like file created OK == C:\junk>del mydata.dat C:\junk>copy con mydata.dat any old codswallop ^Z 1 file(s) copied. === OK, now mydata.dat is trash. C:\junk>c:\python23\python Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import shelve >>> df = shelve.open('mydata.dat', 'c') Traceback (most recent call last): File "<stdin>", line 1, in ? File "c:\python23\lib\shelve.py", line 231, in open return DbfilenameShelf(filename, flag, protocol, writeback, binary) File "c:\python23\lib\shelve.py", line 212, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback, binary) File "c:\python23\lib\anydbm.py", line 80, in open raise error, "db type could not be determined" anydbm.error: db type could not be determined >>> Uh-huh. By the way, it's probably not a good idea to use a ".dat" extension; evidently (read whichdb.py for the gory details) some of the dbms add an extension to the supplied name. One of them uses ".dat". Could become a source of confusion. Take a hint: they say "Google is your friend", but better still is the source in lib\*.py -- it's quite legible, you don't need an Internet connection, and there sure ain't no ads in the margin. And don't just open it in emergencies: pick a module that covers a topic that interests you and just read it. You'll see good coding style, good ways of doing things, wise utterances by the timbot, ... HTH, John -- http://mail.python.org/mailman/listinfo/python-list