Scope of decorator argument

Gregor Horvath gh at gregor-horvath.com
Tue Oct 17 03:41:52 EDT 2006


Gregor Horvath schrieb:
> 
> Is there any other solution, probably with metaclasses ?
> 

I've found this one:

class mymeta(type):
    def __new__(meta, class_name, bases, new_attrs):
        new_attrs["edit"] = adecorator(new_attrs['xy'])(bases[0].edit))
        return type.__new__(meta, class_name, bases, new_attrs)

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

class child(base):
    __metaclass__ = mymeta
    xy = 3


Don't know if it's the best solution but it seems to work.

-- 
  Servus, Gregor




More information about the Python-list mailing list