abstraction of the column names (classes)

Wiebke Pätzold wiebke.paetzold at mplusr.de
Tue Aug 5 08:52:17 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'.
Now I want to abstract the column name 'Nachname'. So I search in an
unknown column. Only the user of the program should determine in wich
class the search takes place. This input should happen in the view
lines of testing the class.
My task is it to change the program that a abstraction of the column
names takes place.
Please give me a detailed answer. If it is possible the changed
program because I am very new in Python and I am orientationless.

This is the program

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
    





More information about the Python-list mailing list