Cell objects and their values
Michael Hudson
mwh at python.net
Thu Apr 22 06:34:13 EDT 2004
"Robert Brewer" <fumanchu at amor.org> writes:
> Jeff Epler wrote:
> > This seems to work, but it's undocumented (specifically,
> > func_closure as
> > an argument to new.function is undocumented) and makes my tummy feel
> > funny when I think about it.
> >
> > >>> import new
> > >>> def cell_get(cell):
> > ... def f(): return cell
> > ... return new.function(f.func_code, {}, "f", (), (cell,))()
> > ...
>
> Rock. On.
>
> That is frickin' brilliant in at least three ways I never would have
> thought of. :) Thanks! Looking back over Raymond's bytecode hack in PEP
> 329, I notice he also used func_closure as an arg to function(). In
> addition, he avoided importing the "new" module by just calling
> type(f)().
That wouldn't work in Python 2.2, I don't know what Jeff is using
these days...
Cheers,
mwh
--
On the other hand, the following areas are subject to boycott
in reaction to the rampant impurity of design or execution, as
determined after a period of study, in no particular order:
... http://www.naggum.no/profile.html
More information about the Python-list
mailing list