renaming 'references' to functions can give recursive problems

Antoon Pardon apardon at forel.vub.ac.be
Wed Feb 16 10:32:55 EST 2005


Op 2005-02-16, peter schreef <Peter.Vandersteegen at gmail.com>:
> Hello all,
>
> Recently I've started to refactor my code ...(I'm using python 2.3.4)
> I tried to add extra functionality to old functions non-intrusively.
> When I used a construct, which involves renaming functions etc... I
> came across some recursive problems.  (a basic construct can be found
> under the section BASIC CODE)
>
> These problems do not occur when renaming objects.  (see section EXTRA
> CODE)
> My question now is:
> I do not know the underlying idea of functions.  Is this the way they
> should behave? Or should they work the same way as objects do?
> (My preferences goes to this last option)
>
> BASIC CODE:
> ---------------------------------------------------------------------------
> def fA(input): # starting point: function named fA
>     return input
>
> def newFA(input): # new function with added functionality
>     #does something extra with a!
>     return fA(input)
> fA = newFA
>      # this should allow to add functionality without
>      # breaking older code which uses the name fA!
> fA() # execute fA()

Try this:

def fA(input):
  return input


def newFA(input, f= fA):
  return f(input)

fA = newFA

-- 
Antoon Pardon



More information about the Python-list mailing list