classes (table)

Wiebke Pätzold wiebke.paetzold at mplusr.de
Wed Aug 6 06:56:07 EDT 2003


Hi all,

I create a database that contains a table. 'Nachname'  is one of 13
column names. This program can search for
a special letter. In my example it is 'ra'. and the search takes place
in 'Nachname'. 'ra' takes place within a word. This is solved with
regular expression. So that I can limit my search.
For example: I can search for 'ra' and it is not relevant wich letters
follow or wich letters are in front of 'ra'.
This is the program that I wrote:

import sys
import Mk4py
import re

db = Mk4py.storage("c:\\datafile.mk",1)
vw = db.view("people")

class PatternFilter:
    def __init__(self, pattern):
        self.pattern = re.compile(pattern)

    def __call__(self, row):
        try:
            nachname = row.Nachname
        except AttributeError:
            return 0
        return self.pattern.search(nachname)is not None

vf = vw.filter(PatternFilter("ra.*"))

for r in vf:
    print  vw[r.index].Nachname


The program should have two possibilities to search for regular
expressions. The first possibility is in this program. Here I can
look for a certain expression. In my example I can look for 'ra' and
it is not relevant wich letters follow or wich letters are in front of
'ra'. But this search can ONLY takes place in the column 'Nachname'.
'Nachname is fixed by the programmer.
The second possibility is that the user and NOT the programmer
determine the column name in which the user want to look for a regular
expression. Only the user can determine in  which column the search
takes place.
These 2 kinds of the search must be combined in the program.

I hope somebody can help me with my problem!

Wiebke

    





More information about the Python-list mailing list