Is there a way to change the closure of a python function?
jmp
jeanmichel at sequans.com
Tue Sep 27 10:41:13 EDT 2016
On 09/27/2016 04:01 PM, Peng Yu wrote:
> Hi, In many other functional language, one can change the closure of a
> function. Is it possible in python?
>
> http://ynniv.com/blog/2007/08/closures-in-python.html
>
If I understood correctly your link:
(untested)
def func(x):
return x+func.y
func.y = 10
func(5) => 15
func.y = 100
func(5) => 105
implements a closure of a function.
jm
Note: function are objects, and can have attributes, however I rarely
see usage of these, there could be good reasons for that.
More information about the Python-list
mailing list