Re: How to add a Decorator to a Class Method

2007-11-20 Thread Laszlo Nagy
>> Can new_func reference self? Would self just be one of the args? >> >> -Greg >> > > For methods, self is always "just one of the args". When the > decorator is applied to a method, self will be args[0] in new_func. > If you want to use the name "self" instead of args[0] you can: def

Re: How to add a Decorator to a Class Method

2007-11-20 Thread [EMAIL PROTECTED]
On Nov 20, 12:32 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Nov 20, 2:05 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > > > > On Mon, 19 Nov 2007 20:59:51 -0800, [EMAIL PROTECTED] wrote: > > > How do I add a decorator to a class method? Here's what I want to do, > > > but

Re: How to add a Decorator to a Class Method

2007-11-20 Thread Laszlo Nagy
> Thanks those answers make sense. But for this function if defined > outside the class: > > >> def pre(fn): >> def new_func(*args, **kwargs): >> print "'hi'" >> fn(*args, **kwargs) >> return new_func >> > > Can new_func reference self? Would self just be one of t

Re: How to add a Decorator to a Class Method

2007-11-20 Thread [EMAIL PROTECTED]
On Nov 20, 2:05 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Mon, 19 Nov 2007 20:59:51 -0800, [EMAIL PROTECTED] wrote: > > How do I add a decorator to a class method? Here's what I want to do, > > but I guess my syntax isn't right. Any advice? > > > class A: > > def pre(self,f

Re: How to add a Decorator to a Class Method

2007-11-19 Thread Marc 'BlackJack' Rintsch
On Mon, 19 Nov 2007 20:59:51 -0800, [EMAIL PROTECTED] wrote: > How do I add a decorator to a class method? Here's what I want to do, > but I guess my syntax isn't right. Any advice? > > class A: > def pre(self,fn): > def new_func(*args,**kwargs): > print 'hi' >

Re: How to add a Decorator to a Class Method

2007-11-19 Thread Arnaud Delobelle
On Nov 20, 4:59 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > How do I add a decorator to a class method? Here's what I want to do, > but I guess my syntax isn't right. Any advice? > > class A: > def pre(self,fn): > def new_func(*args,**kwargs): > print 'hi' >

Re: How to add a Decorator to a Class Method

2007-11-19 Thread Jeff McNeil
Think about the context in which your function definition is executed and how the 'self' parameter is implemented. Your definitions (and decorator calls) are executed in the context of 'class A.' That said, the following would work: >>> class A: def pre(fn): def new_func(*args,**kwa

How to add a Decorator to a Class Method

2007-11-19 Thread [EMAIL PROTECTED]
How do I add a decorator to a class method? Here's what I want to do, but I guess my syntax isn't right. Any advice? class A: def pre(self,fn): def new_func(*args,**kwargs): print 'hi' fn(*args,**kwargs) return new_func @self.pre def func(self,