Howto MACRO in python ?

Richie Hindle richie at
Wed Aug 13 11:05:42 CEST 2003

> 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?

I meant function attributes.  Then, Bill could write something like:

def test1():
    print "Hello",

test1.DEBUG_LEVEL = 10

instead of hijacking a local variable to do the job.  And you could do
things like this (in extreme pseudocode because I don't have time to look
at the `inspect` docs) -

def instrumentMyStuff(level):
    for module in ['the', 'modules', 'to', 'instrument']:
        for function in inspect.getfunctions(module):
            function.DEBUG_LEVEL = level
        for klass in inspect.getclasses(module):
            for method in inspect.getmethods(klass):
                method.im_func.DEBUG_LEVEL = level

which makes using sys.settrace worthwhile (if you have to use a local
variable then you might as well just have a TRACE function as in Bill's
original example).

> When a frame is executed, the function is no longer available

That's a shame.

Richie Hindle
richie at

More information about the Python-list mailing list