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 enou

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 -- http://mail.python.org/mailman/listinfo/python-list

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

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 w

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 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): .wrappedf.counte

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: -

adding new functionality to a function non-intrusively!

2005-02-16 Thread peter
Hello all, Recently I've started to refactor my code ... I would like to add extra functionality to a function !non-intrusively! (not rewriting the old code is really important) How can I achieve this? Thus I start with an old function named fA. I would like to add extra functionality to fA. Esse