By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

Question: Best Practice? (module 'shelve')

P: n/a
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) = email
self.dbName = dbName
self.emailList = []

def match(self, src, url):
self.matchDict = {}
self.matchDict[url] = {}
# The next 2 functions just add stuff to self.matchDict
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.db[url] = self.matchDict[url]
# 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 ='textmatch.db', flag=modeflag)
self.db =, flag=modeflag)

Jan 10 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.