Modifying func_closure

Michael Hudson mwh at python.net
Fri Jul 9 09:51:13 EDT 2004


Jacek Generowicz <jacek.generowicz at cern.ch> writes:

> On 8 Jul 2004, at 18:38, Robert Brewer wrote:
> 
> > Jacek Generowicz wrote:
> >> Python's closures are read-only. But is there a way of hacking one's
> >> way around this restriction?
> 
> > If I understand your requirements correctly, I would use
> > new.function(),
> > passing it the closure you want.
> >
> > return new.function(co, f.func_globals, newname, f.func_defaults,
> > f.func_closure)
> 
> But this doesn't help me to modify the binding in an original closure
> ... unless I'm missing your point.

No, not really.  I think Robert is saying that often times doing what
he suggests is sufficient.  Not always, though.

Cheers,
mwh

-- 
  <dash> if python is an orchestra, overloaded operators are
        "miscellaneous percussion"              -- from Twisted.Quotes



More information about the Python-list mailing list