Classes in Python

Alexander Schmolck a.schmolck at gmx.net
Mon Aug 4 13:08:55 CEST 2003


Wiebke Pätzold <wiebke.paetzold at mplusr.de> writes:

> Hi all!
> 
> Could somebody help me with a task?

I don't know what exactly you're trying to do (I don't know Mk4py), but...

> 
> import sys
> import Mk4py
> import re
> 
> db = Mk4py.storage("c:\\datafile.mk",1)
> vw = db.view("people")
> 
> class PatternFilter:
>     def _init_(self, pattern):
         __init__

>         self.pattern = re.compile(pattern)
> 
>     def _call_(self, row):
         __call__

>         try:
>             nachname = row.Nachname
>         except AttributeError:
>             return 0
>         return self.pattern.search(nachname)is not None
> 
> vf = vw.filter(PatternFilter("Ge.*"))

Before posting this, you should really have tried something like:

  class Dummy:
        Nachname = 'Some name'
  PatternFilter("Ge.*")(Dummy)

> 
> for r in vf:
>     print  vw[r.index].Nachname
>     
> 
> 
> I wrote this program, but it returns nothing. I can't find the error.

Well, given the two errors I found, it would seem strange to me that it
vw.filter doesn't moan about PatternFilter("Ge.*") being not callable.


> Can somebody help me? 
> Can somebody tell me why the part:   "class PatternFilter:"  doesn't
> return the expressions it should return?


'as




More information about the Python-list mailing list