Howto MACRO in python ?
Richie Hindle
richie at entrian.com
Wed Aug 13 05:05:42 EDT 2003
[Richie]
> Anyone know how I could retrieve function attributes from within a trace
> function? It would be neater.
[Chris]
> 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 entrian.com
More information about the Python-list
mailing list