creating classes with mix-ins

Carl Banks pavlovevidence at gmail.com
Tue May 12 18:38:18 EDT 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