Re: dinamically altering a function

2005-03-12 Thread Bengt Richter
On Sat, 12 Mar 2005 23:09:58 -0400, vegetax <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: [...] >> Please pretend things worked the way you want, and post an example. Maybe >> we can make it work. >> >> Regards, >> Bengt Richter > >Ok , the complete use case is : > >def fun1(a,b,obj = None): >

Re: dinamically altering a function

2005-03-12 Thread vegetax
Bengt Richter wrote: > On Sat, 12 Mar 2005 18:19:36 -0400, vegetax <[EMAIL PROTECTED]> wrote: > >>Steven Bethard wrote: >> >>> vegetax wrote: I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def de

Re: dinamically altering a function

2005-03-12 Thread vegetax
thanks , i guess the best option is a callable class which builds the functions with the common code. Once again,we REALLY need a patterns book for python. =/ -- http://mail.python.org/mailman/listinfo/python-list

Re: dinamically altering a function

2005-03-12 Thread Bengt Richter
On Sat, 12 Mar 2005 18:19:36 -0400, vegetax <[EMAIL PROTECTED]> wrote: >Steven Bethard wrote: > >> vegetax wrote: >>> I i need a decorator that adds a local variable in the function it >>> decorates, probably related with nested scopes, for example: >>> >>> def dec(func): >>> def wrapper(obj

Re: dinamically altering a function

2005-03-12 Thread Jeremy Bowers
> What i want is to declare in the decorator some code that is common to all > these functions, so the functions assume that the decorator will be there > and wont need to duplicate the code provided by it, and the functions are > not known ahead of time, it has to be dynamic. This sounds like a c

Re: dinamically altering a function

2005-03-12 Thread Steven Bethard
vegetax wrote: Steven Bethard wrote: Have you considered using OO here? You might find that this is more easily written as: py> class Object(object): ... pass ... py> class fun(object): ... def __new__(self, *args): ... if len(args) == 2: ... obj, b = args ... e

Re: dinamically altering a function

2005-03-12 Thread vegetax
Steven Bethard wrote: > vegetax wrote: >> I i need a decorator that adds a local variable in the function it >> decorates, probably related with nested scopes, for example: >> >> def dec(func): >> def wrapper(obj = None): >> if not obj : obj = Obj() >> >> return func() >> >>

Re: dinamically altering a function

2005-03-12 Thread Steven Bethard
vegetax wrote: I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def dec(func): def wrapper(obj = None): if not obj : obj = Obj() return func() return wrapper() @dec() def fun(b): obj.desc = 'marke

dinamically altering a function

2005-03-12 Thread vegetax
I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def dec(func): def wrapper(obj = None): if not obj : obj = Obj() return func() return wrapper() @dec() def fun(b): obj.desc = 'marked' obj.