Classes in Python

Fredrik Lundh fredrik at pythonware.com
Mon Aug 4 09:07:17 EDT 2003


Wiebke Pätzold wrote:

> 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.*"))
>
> for r in vf:
>     print  vw[r.index].Nachname
>
> I wrote this program, but it returns nothing. I can't find the error.
> Can somebody help me?
> Can somebody tell me why the part:   "class PatternFilter:"  doesn't
> return the expressions it should return?

note that built-in hooks like __init__ and __call__ uses *two* underscores
on each side of the keyword.

not sure why vw.filter doesn't give you an exception, but your Pattern-
Filter instance is neither initialized nor callable.

</F>








More information about the Python-list mailing list