union in Python
Wiebke Pätzold
wiebke.paetzold at mplusr.de
Tue Aug 12 04:11:47 EDT 2003
import sys
Hi all,
At the beginning there is a table (database) with different columns.
So I create a search operator to look for regular expressions. First I
start the search only in one column and the program run. Now I want to
expand the search. The search have to take place in 2 columns. In my
example it is "Themenbereiche" and "Nachname". I tried something. But
the program doesn't run.
Can somebody help with the release of the error?
import Mk4py
import re
db = Mk4py.storage("c:\\datafile.mk",1)
vw = db.view("people")
class PatternFilter:
def __init__(self, pattern, feld):
self.feld = feld
self.pattern = re.compile(pattern)
def __call__(self, row):
try:
exec(self.feld+" = row."+self.feld)
except AttributeError:
return 0
return self.pattern.search(eval(self.feld))is not None
def union1(feld_th, feld_na):
result = []
for i in feld_th+feld_na:
if i not in result:
result.append(i)
return result
def union2(feld_th, feld_na):
result = {}
for i in feld_th+feld_na:
tmp[i] = 1
return tmp.keys()
feld_th = "Themenbereiche"
vf = vw.filter(PatternFilter("do.*", feld_th))
feld_na = "Nachname"
vf = vw.filter(PatternFilter("im.*", feld_na))
print feld_th, feld_na, union1(feld_th, feld_na)
print feld_th, feld_na, union2(feld_th, feld_na)
More information about the Python-list
mailing list