[Python-Dev] getting at the current frame
M.-A. Lemburg
mal@lemburg.com
Tue, 24 Oct 2000 22:45:28 +0200
"Barry A. Warsaw" wrote:
> [...]
> All well and good and doable in Python today, except getting the
> current frame with the exception raising trick is slooow. A simple
> proposed addition to the sys module can improve the performance by
> about 8x:
>
> def _(s):
> frame = sys.getcaller(1)
> d = frame.f_globals.copy()
> d.update(frame.f_locals())
> return the_translation_of(s) % d
>
> The implementation of sys.getcaller() is given in the below patch.
> Comments? I think this particular addition is too small for a PEP,
> although ?!ng still owns PEP 215 (which needs filling in).
+1.
I have a similar function in mxTools. I would use a different
name though... something like "sys.getframe()".
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/