I would like to define a log function that is called with a message followed by one or more variables to be printed out. So, something like the following:
log( "Oh no, error.", x, d)
log would be defined sorta like:
def log( msg, *arg):
# Loop through arg, printing caller's variable's name and value.
This would log to a file the following:
Oh no, error.
x = 5
d = { foo: "Foo", goo: "Goo" }
Can this be done at all? I can print locals and arguments using inspect, but I don't know if I can iterate through values in the current frame, using the variable names of a previous frame. (locals
in inspect.getargvalues(previousFrame)
has the names, but lots of other names too.)