[Tutor] Decorators, I am confused.

David Driver count0.djd at gmail.com
Fri Jul 15 02:46:22 CEST 2005

What I would like to do is something like this:

class testObj(object):
    _rules = list()
    def evalRules(self):
        for r in _rules:
    def rule(func):
        if not func in func.__class__._rules:
            print testis._rules
        return func
    def arule(self):
        print a

Of course it doesn't work. Is there a way to make it work? What I am
trying to do is make a collection of validation rules that can be
iterated and capture raised exceptions to be returned at the end of
eval rules.

I am trying to replace somethng that looks like this:

class testObj(object):
    def _init__(self):
        self._rules = list((self.arule,
    def evalRules(self):
        for r in self._rules:

It would be too easy to add a rule twice or forget to add the rule to
the list in a subclass. I thought that using a decorator would make it


See there, that wasn't so bad.

More information about the Tutor mailing list