Re: adding new functionality to a function non-intrusively!

2005-02-16 Thread mjs7231
Whenever I want to add functionality to a function while still allowing it to word as it was before my edit would be to include a few optional variables passed to the string. something to this effect would look like: -- BEFORE:

Re: adding new functionality to a function non-intrusively!

2005-02-16 Thread Michele Simionato
Decorators are your friends. You can wrap a function and give it additional functionality. For instance just yesterday I needed to keep track of how many times a function is called. This can be done with this decorator: .def with_counter(f): .def wrappedf(*args, **kw): .

Re: adding new functionality to a function non-intrusively!

2005-02-16 Thread peter
Hello I indeed also rely on your idea. My problem however is: is has to be non-intrusively in both ways. In your example, it would indeed not break the old code which relies on myfunction but my problems is: I also do not want to change the code of the 'before' myfunction. so my problem in fact

Re: adding new functionality to a function non-intrusively!

2005-02-16 Thread peter
thx a lot for the information on decorators this will be very usefull... (sounds like a little step towards aspect orientated programming,:) ) Because I use libraries which rely on boost-python I can not jump into python 2.4 but I understand the main idea and can also use it in python 2.3 (it

Re: adding new functionality to a function non-intrusively!

2005-02-16 Thread Terry Reedy
peter [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] so my problem in fact is: BEFORE: def myfunction(a,b): return (a+b) AFTER: def myfunction(a,b, op=add): if (op == add): # some function which calls the old code for myfunction Is this wrapping what

Re: adding new functionality to a function non-intrusively!

2005-02-16 Thread peter
indeed it does, so basically everything works except my original solution: def myfunction(a,b): return a+b def _myfunction(a,b): return myfunction(a,b) myfunction = _myfunction oh well, it was enough to puzzle my tiny brain --

Re: adding new functionality to a function non-intrusively!

2005-02-16 Thread Terry Reedy
peter [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] indeed it does, so basically everything works except my original solution: def myfunction(a,b): return a+b def _myfunction(a,b): return myfunction(a,b) myfunction = _myfunction oh well, it was enough to puzzle