472,334 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

anydbm bug ?

According to the Python Library Reference invoking anydbm.open() with flag
value 'n' should always create a new empty database. However, the following
code produces an error. I stumbled upon this while writing some test code.
Opening and closing the file before invoking anydbm.open() was an attempt to
delete the results of a previous test. Does this indicate a bug in anydbm?

import anydbm
filename = r'C:\My Documents\Python\misc\testdb.tmp'
f = open(filename, 'w')
f.close()
file = anydbm.open(filename, 'n')

produces:

PythonWin 2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (mh******@skippinet.com.au) - see
'Help/About PythonWin' for further copyright information.
Traceback (most recent call last):
File
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py" ,
line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\My Documents\Python\PicDas_\Script1.py", line 5, in ?
file = anydbm.open(filename, 'n')
File "C:\PYTHON22\LIB\anydbm.py", line 83, in open
raise error, "db type could not be determined"
error: db type could not be determined


Jul 18 '05 #1
2 1513
Gary Richardson fed this fish to the penguins on Thursday 04 December
2003 08:07 am:


According to the Python Library Reference invoking anydbm.open() with
flag value 'n' should always create a new empty database. However, the
following code produces an error. I stumbled upon this while writing
some test code. Opening and closing the file before invoking
anydbm.open() was an attempt to delete the results of a previous test.
Does this indicate a bug in anydbm?
If you look at the code for anydbm, the first thing it does is see if
the file exists using whichdb. whichdb is finding the file that you
nulled the contents of, and is unable to determine the type of db file
it found. The "n" flag is only checked /if/ no file is found, otherwise
it is passed to the dbm module selected by whichdb.

Read the paragraph /above/ the one that describes the flags:

"""
If the database file already exists, the whichdb module is used to
determine its type and the appropriate module is used; if it does not
exist, the first module listed above that can be imported is used.
"""

Your open(w)/close() sequence leave a file in place. whichdb is
finding that file, then failing to determine the dbm module that
handles the contents. It is the dbm-specific module that handles the
"n" flag to create a new (which I interpret to me: using the dbm module
that the file /already/ if formatted for, delete all records, leave
file open for use)
Rather than using open/close, why not just delete the file en toto?

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #2
On Thu, 4 Dec 2003, Gary Richardson wrote:
According to the Python Library Reference invoking anydbm.open() with flag
value 'n' should always create a new empty database. However, the following
code produces an error. I stumbled upon this while writing some test code.
Opening and closing the file before invoking anydbm.open() was an attempt to
delete the results of a previous test. Does this indicate a bug in anydbm?

import anydbm
filename = r'C:\My Documents\Python\misc\testdb.tmp'
f = open(filename, 'w')
f.close()
file = anydbm.open(filename, 'n')


I don't think there's a bug in anydbm, though the docs perhaps should make
clear that you should make sure any db files are removed before attempting
to create a new db.

truncation is a poor way to attempt to get rid of anything that might
exist - if it exists, delete it.

--
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: an*****@bullseye.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.org.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John D. | last post by:
Does anyone have any good example code that shows how to use the "anydbm"wrapper tp interface with a very simple database. like some examples ofhow...
1
by: Alessandro Crugnola *sephiroth* | last post by:
Hi all I'm trying to compile a python app with py2exe (not the 0.5.0.. i think 0.4.1) which uses the anydbm module But when i launch the exe file...
1
by: Anton Sherwood | last post by:
Rather newbie question here. My current project will build a database of solutions to a topology problem, which I'll eventually put (readonly) on...
1
by: Derek Basch | last post by:
Hello, I have a CGI script which uses anydb.open() to create a DBM. However I get this traceback: /usr/lib/python2.3/bsddb/__init__.py in...
0
by: Eric S. Johansson | last post by:
I have a preference for gdbm when building DBM based dictionaries but have found I cannot count on it being there all the time. Therefore, I have...
6
by: aomighty | last post by:
I wanted to write the following code: import shelve try: db = shelve.open(file, "r") except SomeError: print "Oh no, db not found" Only,...
0
by: chris | last post by:
I need simple data persistence for a cgi application that will be used potentially by multiple clients simultaneously. So I need something that...
6
by: davidj411 | last post by:
anydbm and dictionary{} seem like they both have a single key and key value. Can't you put more information into a DBM file or link tables? I just...
0
by: Torsten Bronger | last post by:
Hallöchen! A TurboGears process opens a DB file with anydbm and keeps it open. The the same time, this file is updated by another process. How...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.