Cell objects and their values
Robert Brewer
fumanchu at amor.org
Thu Apr 22 01:31:01 EDT 2004
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)().
Danke.
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list