creating classes with mix-ins

Carl Banks pavlovevidence at gmail.com
Wed May 13 00:38:18 CEST 2009


On May 12, 4:45 am, samwyse <samw... at gmail.com> wrote:
> Unfortunately, 'boilerplate()' uses the handlers that I provide when
> MetaBlog is instantiated.

In that case, the handler functions should be attributes of the
instance, not of the class.  Do something like this:

class MetaBlog(object):
    def __init__(self):
        self.blog = blogHander()
        for name in self.blog.get_methods():
            setattr(self,name,self.boilerplate(name))

    def boilerplate(self,name):
        method = getattr(self.blog,name)
        def template(*args):
            self.do_verification_here()
            method(*args)
        return template


Carl Banks



More information about the Python-list mailing list