On 6/18/2013 2:38 PM, skunkwerk wrote:
Hi, I'm writing a custom profiler that uses sys.settrace. I was wondering if there was any way of tracing the assignments of variables inside a function as its executed, without looking at locals() at every single line and comparing them to see if anything has changed.
The stdlib has an obscure module bdb (basic debugger) that is used in both pdb (python debugger) and idlelib.Debugger. The latter can display global and local variable names. I do not know if it does anything other than rereading globals() and locals(). It only works with a file loaded in the editor, so it potentially could read source lines to looks for name binding statements (=, def, class, import) and determine the names just bound. On the other hand, re-reading is probably fast enough for human interaction.
My impression from another issue is that traceing causes the locals dict to be updated with each line, so you do not actually have to have to call locals() with each line. However, that would mean you have to make copies to compare.
-- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list