Scope of decorator argument

Gregor Horvath gh at
Tue Oct 17 08:34:38 CEST 2006



class base(object):
    def edit(self):
        print "edit"

class child(base):
    xy = 3

obviously fails because "xy" is not bound at class creation time of the
base object.

One solution could be delegation:

class base(object):
    def edit(self):
        print "do the real work here"

class child(object):
    xy = 3
    mybase = base

    def edit(self, *args, **kwargs):
        self.mybase.edit(*args, **kwargs)

But then I have the ugly boiler plate delegation code in child.

Is there any other solution, probably with metaclasses ?

  Servus, Gregor

More information about the Python-list mailing list