Classes in Python

Heiko Wundram heikowu at
Mon Aug 4 19:07:00 CEST 2003

On Mon, 2003-08-04 at 12:30, Wiebke Pätzold wrote:
> class PatternFilter:
>     def _init_(self, pattern):
>         self.pattern = re.compile(pattern)

Python special functions are always prefixed/postfixed by two
underscores, so let this read __init__

> [snip]
> vf = vw.filter(PatternFilter("Ge.*"))

Moans here with a "__init__ takes only one argument, got two instead",
when I try to run it. Next time you post code, read the error message,
and this should've pointed you at the fact that _init_ isn't called, but
__init__ is.

When this was corrected, Metakit would've moaned that the filter wasn't
callable, this would've made you look up the syntax for callable in the
Python documentation, which would've
led you to the documentation on callable instances having a __call__

And so on. Next time you post something, please include the correct
error message (this program doesn't run at all, of course this means it
doesn't return anything, but the exception traceback would've been
helpful), and having a look at the Python documentation before posting
can't harm too...


More information about the Python-list mailing list