regular expression
Wiebke Pätzold
wiebke.paetzold at mplusr.de
Fri Aug 1 05:28:46 EDT 2003
On Thu, 31 Jul 2003 10:46:59 -0500, Jeff Epler <jepler at unpythonic.net>
wrote:
>These are all untested, because I don't have Mk4py or your datafile to
>try it on.
>
>I might write this:
> import re
> pattern = re.compile("^Ge")
> def func(row):
> try:
> nachname = row.Nachname
> except AttributeError:
> return 0
> return pattern.search(nachname) is not None
>
> vf = vw.filter(func)
>
>If you're using a Python version with nested scopes, you could use them
>in this case:
> import re
> def make_func(pattern):
> pattern = re.compile(pattern)
> def func(row):
> try:
> nachname = row.Nachname
> except AttributeError:
> return 0
> return pattern.search(nachname) is not None
> return func
>
> vf = vw.filter(make_func("^Ge"))
>
>or you can make a callable filter object by using classes:
> import re
> 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("^Ge"))
>
>Jeff
thank you for the part of the program.
But I have one question.
If I insert your first suggestion- there is print nothin. Is it
possible that there is missing something?
More information about the Python-list
mailing list