union in Python
Jørgen Cederberg
jorgencederberg at hotmail.com
Tue Aug 12 09:52:11 EDT 2003
Wiebke Pätzold wrote:
> Hi all,
>
> about union I found still something else. Perhaps it is better. But
> here the program doesn't run too.
What are the errors?
> Can me somebody help?
Somebody probably could, but as you haven't described what is wrong it
is very difficult to help you. You could/should copy-paste the
error-traceback that was printed when your program failed.
>
> 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)
Where are the functions union1 and union2 defined and why do you want to
find the union between two strings, it doesn't make sense. On the other
hand, if feld_th and feld_na where two lists it would make sense.
Can you come up with a simpler example, and demonstrate what goes wrong?
I don't have mk4py installed, and don't intend installing it.
regards
Jorgen
More information about the Python-list
mailing list