469,312 Members | 2,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

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 1453
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by John D. | last post: by
1 post views Thread by Alessandro Crugnola *sephiroth* | last post: by
1 post views Thread by Anton Sherwood | last post: by
1 post views Thread by Derek Basch | last post: by
reply views Thread by Eric S. Johansson | last post: by
6 posts views Thread by aomighty | last post: by
reply views Thread by chris | last post: by
reply views Thread by Torsten Bronger | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.