472,328 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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 874

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

Similar topics

1
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...
0
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...
0
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...
0
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...
9
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...
6
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...
0
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...
0
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...
1
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...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.