error: db type could not be determined

N

neutrinman

why does the following error occur?

def quit_time():
data_file = shelve.open("data.dat", "c")
data_file["quit_time"] = datetime.datetime.today()
print data_file["quit_time"]
raw_input("enter")


Traceback (most recent call last):
File "D:\a\TEXT\Py\going_over\going_over.py", line 192, in -toplevel-
main()
File "D:\a\TEXT\Py\going_over\going_over.py", line 190, in main
quit_time()
File "D:\a\TEXT\Py\going_over\going_over.py", line 156, in quit_time
data_file = shelve.open("data.dat", "c")
File "D:\A\UTILITIES\PYTHON\PYTHON23J\lib\shelve.py", line 231, in
open
return DbfilenameShelf(filename, flag, protocol, writeback, binary)
File "D:\A\UTILITIES\PYTHON\PYTHON23J\lib\shelve.py", line 212, in
__init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol,
writeback, binary)
File "D:\A\UTILITIES\PYTHON\PYTHON23J\lib\anydbm.py", line 80, in
open
raise error, "db type could not be determined"
error: db type could not be determined
 
J

John Machin

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.
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.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
 
N

neutrinman

Thank you for your reply, Jhon.
It was useful advice.
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, ...

I am new to programing so I was wasting a lot of time to fix bug, only
struggling with my code where an error has occured then read throug an
book at hand. I didn't think of such an approch to solve problems and
read error messages.

Thank you again very much for the imformative advice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top