adding new functionality to a function non-intrusively!

Terry Reedy tjreedy at udel.edu
Wed Feb 16 13:33:03 EST 2005


"peter" <Peter.Vandersteegen at gmail.com> wrote in message 
news:1108566348.660335.224170 at g14g2000cwa.googlegroups.com...
> 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 you want?

_myfunction = myfunction
def myfunction(a,b, op='add'):
  if (op == 'add'): return _myfunction(a,b)
  # else do new stuff and return

Terry J. Reedy






More information about the Python-list mailing list