union in Python
Wiebke Pätzold
wiebke.paetzold at mplusr.de
Tue Aug 12 09:00:08 EDT 2003
Hi all,
about union I found still something else. Perhaps it is better. But
here the program doesn't run too.
Can me somebody help?
import sys
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 union(feld_th, feld_na):
c = feld_th[:]
for i in range(len(feld_na)):
if feld_na[i] not in feld_th:
c.append(feld_na[i])
return c
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)
Wiebke
More information about the Python-list
mailing list