[Python-Dev] Re: getting at the current frame

barry@wooz.org barry@wooz.org
Tue, 24 Oct 2000 17:34:54 -0400 (EDT)


>>>>> "GvR" == Guido van Rossum <guido@python.org> writes:

    GvR> The other, perhaps more major, problem with this it is that
    GvR> you can't easily wrap functions that use it in other
    GvR> functions.  Normally, if there's a function foo(arg) that
    GvR> does something, I can write a function wrapfoo(arg) that does
    GvR> something else, then calls foo(arg), and then does another
    GvR> thing.  But if foo() uses getframe(), that's not so easy: the
    GvR> call to foo() in wrapfoo() will access wrapfoo()'s frame.

    GvR> A way around this would be to implement foo as a call to
    GvR> (e.g.)  _foo(arg, frame), and define foo(arg) as _foo(arg,
    GvR> sys.getframe()).  Then _wrapfoo(arg, frame) could be defined
    GvR> as a wrapper around _foo(arg, frame) and wrapfoo(arg) as
    GvR> _wrapfoo(arg, sys.getframe()).

Darn good point.  So where could we put it?  It's a useful
introspection device.  If it goes in a separate module, should that
perhaps be called `reflection'?  Or maybe `runtime'?  Or maybe
"sys._getframe()" is good enough.

-Barry