473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1560
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 to use "dumbdbm"? Then perhaps at a later time,...
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 created it raise this error:...
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 my website. The entries are text of varying...
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 hashopen(file='/var/www/bp/predictor/tools.dbm',...
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 created this little tidbit which you call before...
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, I'm not sure what SomeError should be. I tried...
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 can handle locking among writes. Sqlite probably...
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 don't see the benefit except for the persistent...
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 can I tell the TurboGears process to fetch the new...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.