Re: Writing func_closure?

2005-06-09 Thread Michael Hoffman
Fernando Perez wrote: > Yes, I knew of the new.function() approach, but the problem is that I don't > know > how to make a fresh closure for it. I can reuse the closure from a different > function, but the docs don't say how to make a valid closure tuple. >>> def makeclosure(x): ... def _f

Re: Writing func_closure?

2005-06-08 Thread Fernando Perez
Greg Ewing wrote: > As far as I know, there is currently no supported way > of directly creating or modifying cell objects from Python; > it can only be done by some obscure trickery. So the docs > are telling the truth here, in a way. :-) In a twisted, convoluted way :) But thanks for the clari

Re: Writing func_closure?

2005-06-08 Thread Greg Ewing
Fernando Perez wrote: > I can reuse the closure from a different > function, but the docs don't say how to make a valid closure tuple. This is > the typical problem of the stdlib docs, which under-specify what is supposed > to > go into a call and don't give at least a specific example. As far

Re: Writing func_closure?

2005-06-08 Thread Fernando Perez
Michael Hoffman wrote: > Fernando Perez wrote: > > > I am trying to do a run-time modification of a function's closure, > > where I want to modify the value of one of the variables in the closure. > > Out of curiosity, why? Oh, I was just trying to play a little trick inside a tight loop whe

Re: Writing func_closure?

2005-06-08 Thread Michael Hoffman
Fernando Perez wrote: > I am trying to do a run-time modification of a function's closure, > where I want to modify the value of one of the variables in the closure. Out of curiosity, why? > In [21]: def wrap(x): >: def f(y): >: return x+y >: return f >