anydbm can't find type of dbm file

jon_warner at my-deja.com jon_warner at my-deja.com
Wed Feb 7 12:20:57 EST 2001


Hi,

I am a newbie to the Python language, so there may be some errors in the
following source code, but I wonder if you guys could help me work out
what is going on here?

I have written a test program to find out how object persistence works
in Python, and when it is run Python complains that anydbm cannot
determine the dbm file type (i.e. whether it is gdbm orany other type of
dbm file). Here is the code:

#!/usr/bin/python

import sys
import shelve

class link_url:
	def __init__(self, url_link, description, author, type):
		self.url  = url_link
		self.desc = description
		self.auth = author
		self.type = type

def input_url_hand():
	global new_url
	_url = raw_input("What is the name of the URL? ")
	_auth = raw_input("What is your name? ")
	_desc = raw_input("Give a description ")
	_type = raw_input("What type of URL is it? ")
	new_url = link_url(_url, _desc, _auth, _type)

def get_url_link(url_in):
	sys.stdout.write(url_in.url)

def store_link(link_in):
	link_store = shelve.open('my_db')
	link_store[link_in.url]=link_in
	link_store.close

def print_links():
	link_store = shelve.open('my_db')
	for name in link_store.keys():
		print link_store[name]

def test():
	input_url_hand()
	get_url_link(new_url)
	store_link(new_url)
	print_links()

if __name__ == "__main__":
	test()


And when this is run, the output is:

Traceback (innermost last):
  File "link_url.py", line 42, in ?
    test()
  File "link_url.py", line 38, in test
    store_link(new_url)
  File "link_url.py", line 26, in store_link
    link_store = shelve.open('my_db') # open, with (g)dbm filename
  File "/usr/lib/python1.5/shelve.py", line 152, in open
    return DbfilenameShelf(filename, flag)
  File "/usr/lib/python1.5/shelve.py", line 142, in __init__
    Shelf.__init__(self, anydbm.open(filename, flag))
  File "/usr/lib/python1.5/anydbm.py", line 83, in open
    raise error, "db type could not be determined"
anydbm.error: db type could not be determined

Is there anything I can do to correct this? The Python I am using is:

Python 1.5.2 (#1, Sep 17 1999, 20:15:36)  [GCC egcs-2.91.66
19990314/Linux (egcs
- on linux-i386

Thanks in advance,

Jonathan












Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list