473,507 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question: Best Practice? (module 'shelve')

Hello fellows,

I just wanted to know, if there is any best practice concerning
following code:

import re, shelve

class TextMatcher:
def __init__(self, patterns, email=False, dbName='textmatch.db'):
self._initPatterns(patterns)
self.email = email
self.dbName = dbName
if self.email:
self.emailList = []
self.emailList.append(
re.compile(r'[a-zA-Z0-9_.]+@\w+\.\w+'))

def match(self, src, url):
self.matchDict = {}
self.matchDict[url] = {}
# The next 2 functions just add stuff to self.matchDict
if self.email:
self._addEmails(src, url)
self._addPatterns(src, url)
# Is it good practice to open, write and close the db straight
# away? Or is it better to leave it open until the whole program
# has finished, and close it then?
self.openDB(self.dbName)
self.db[url] = self.matchDict[url]
self.db.close()
# I want to del the matchDict each time so it can't grow big.
# Is this good, or should it be left open, too?
del self.matchDict

def openDB(self, dbName=None, modeflag='c'):
if dbName == None:
self.db = shelve.open('textmatch.db', flag=modeflag)
else:
self.db = shelve.open(dbName, flag=modeflag)

Jan 10 '07 #1
0 909

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

Similar topics

1
6709
by: Kris Caselden | last post by:
Python's docs say that Shelve uses Pickle to serialize its data. However, I've noticed that Pickle can maintain internal links, while Shelve cannot. For instance: >>> d =...
0
2024
by: ex laguna | last post by:
Hi, I have ran into a problem with py2exe 0.5.0 and shelve in python 2.3.3. The script works fine standalone, but not with py2exe. Does anyone have a solution of workaround for this? Thanks...
0
1106
by: Buster McFadden | last post by:
I've run into a problem on this platform (amd64) with code that works elsewhere, on x86, sparc, and ppc platforms. The shelve module is throwing an error raised from the anydbm call inside it: ...
0
1352
by: Ray O | last post by:
I have read a number of threads relating to problems with shelve, but I couldn't find one directly related my experience, so I would appreciate some advice. The closest one ended with a...
9
1669
by: Henning Kage | last post by:
I'm using Python only for some months now and I'm wondering, whether such assignments as above are creating bitwise copies of an object or just recieve a reference. That means I wanted to know,...
6
2013
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following...
0
843
by: Gabriel Genellina | last post by:
En Mon, 28 Apr 2008 02:08:31 -0300, tarun <tarundevnani@gmail.comescribió: By default, each time you do d you get a *different* object. A shelve isn't very smart: it stores a string...
0
889
by: Guillaume Bog | last post by:
Hello, I read and re-read "Python in a Nutshell" written by Alex Martelli, who knows what he is talking about. I'm a bit new to python and I'm going to start doing persistence side on a project....
1
1578
by: Gabriel Genellina | last post by:
En Sun, 18 May 2008 00:14:19 -0300, Guillaume Bog <guibog@gmail.comescribió: A shelve is just a persistent dictionary that uses pickle to store the objects. If you want to store one or a few...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
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,...
0
7376
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...
1
7031
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...
0
5623
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,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1542
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 ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.