Is it possible in python to create an un-linked copy of a function? For example, if I have
a = lambda(x): x
b = lambda(x): a(x)+1
I want b(x)
to always return x+1
, regardless if a(x)
is modified not. Currently, if I do
a = lambda(x): x
b = lambda(x): a(x)+1
print a(1.),b(1.)
a = lambda(x): x*0
print a(1.),b(1.)
the output is
1. 2.
0. 1.
Instead of being
1. 2.
0. 2.
as I would like to. Any idea on how to implement this? It seems that using deepcopy
does not help for functions. Also keep in mind that a(x)
is created externally and I can't change its definition. I've also looked into using this method, but it did not help.