473,699 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\Pytho n\misc\testdb.t mp'
f = open(filename, 'w')
f.close()
file = anydbm.open(fil ename, '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******@skipp inet.com.au) - see
'Help/About PythonWin' for further copyright information.
Traceback (most recent call last):
File
"C:\Python22\Li b\site-packages\Python win\pywin\frame work\scriptutil s.py",
line 301, in RunScript
exec codeObject in __main__.__dict __
File "C:\My Documents\Pytho n\PicDas_\Scrip t1.py", line 5, in ?
file = anydbm.open(fil ename, 'n')
File "C:\PYTHON22\LI B\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 1575
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.netc om.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\Pytho n\misc\testdb.t mp'
f = open(filename, 'w')
f.close()
file = anydbm.open(fil ename, '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*****@bullsey e.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.or g.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
1600
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, I'm going to want tothen interface it to a more robust database like PostGreSQL or mySQL. ButI want to external interface to "hide" the specifics and have a reallygeneric interface. I already played with Python's interface with PostGreSQL, ...
1
2680
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: exceptions.ImportError, no dbm clone found; tryed Is there a way to use the anydbm module anyway? thanks in advance
1
1917
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 length. The keys are likewise of varying length. Is anydbm the way to go? Is shelve anything more than a wrapper for it? Should I be looking at something else?
1
3084
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', flag='c', mode=438, pgsize=None, ffactor=None, nelem=None, cachesize=None, lorder=None, hflags=0) 190 if ffactor is not None: d.set_h_ffactor(ffactor) 191 if nelem is not None: d.set_h_nelem(nelem)
0
1190
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 opening your anydbm database to bias the preference towards gdbm instead of dbhash: # bias DBM towards gdbm if at all possible. def bias_anydbm(): """bias anydbm to gdbm""" try:
6
4443
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 error, anydbm.error, shelve.open.anydb.error, etc. but can't find it. Things
0
819
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 does this, but I am using Python 2.4.4, which does not include sqlite. The dbm-style modules would probably be fine, but I have no idea if they are "write safe" (I have no experience with the underlying unix stuff). Any tips appreciated. ...
6
1589
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 storage. d= dbm.open('c:\\temp\\mydb.dat','n') It has the following interface (key and data are strings): d = data # store data at key (may override data at
0
1138
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 values? my_db.sync() didn't help -- apparently, it only *writes* to the DB file but doesn't read new data from it. Tschö, Torsten.
0
8705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8899
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7785
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.