Howto MACRO in python ?

Christian Tismer tismer at
Tue Aug 12 20:39:39 CEST 2003

Richie Hindle wrote:


> Anyone know how I could retrieve function attributes from within a trace
> function?  It would be neater.

Do you really mean function attributes, or just
local variables? The latter are easily obtainable
through the frame's f_locals.

If you are just after the locals, you don't need to read on.

When a frame is executed, the function is no longer
available, just the source filename (from the code
object), the name of the function and the frame's f_lineno.

Guessing the function object from this info is not
guaranteed to work, but will probably work if your
code is static (not created dynamically, compiled
and thrown away after starting it).
With some luck, you can use the filename and the
function name, import the according module and
get the function object by the name.
Then you can use function attributes.

cheers - chris

Christian Tismer             :^)   <mailto:tismer at>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship*
14109 Berlin                 :     PGP key ->
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?

More information about the Python-list mailing list