Il giorno lun, 22/04/2013 alle 13.53 +0200, Pietro Battiston ha scritto: > Il giorno lun, 22/04/2013 alle 10.27 +0200, Marco Giusti ha scritto: > > On Mon, Apr 22, 2013 at 08:58:39AM +0200, Pietro Battiston wrote: > > [...] > > >[...] > > > > > > Il mio problema è semplicemente che i due > > > print "self is", self > > > stampano due cose diverse. > > > > normale perché sono due cose diverse: [...]. Forse è per questo che non si > > vede spesso oggetti usati > > come decoratori. > > > > A questo punto mi chiedo l'utilità di avere una classe come decoratore. > > Incapsulazione? Ereditarietà? > > > [...] > > Alla luce del tuo chiarimento però mi è chiaro che questo modo di > operare è _meno_ potente...
Ritratto: http://www.outofwhatbox.com/blog/2010/07/python-decorating-with-class/ Sostanzialmente la soluzione è aggiungere alla classe decoratore il metodo def __get__(self, obj, ownerClass=None): # Return a wrapper that binds self as a method of obj (!) return types.MethodType(self, obj) e aspettarsi in __call__ il "self" dell'altra classe come secondo argomento: def __call__(self, otherself, *args): print "self is", self print "otherself is", otherself print "args are", args print "inside myDecoratorC.__call__()" Ho provato. Funziona. Con calma finirò anche per capire perché... ciao Pietro _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python