Rex Eastbourne wrote: > Thanks. I adapted it a bit: > > def debug(foo): > print foo, 'is:' > exec('pprint.pprint(' + foo + ')') > > But I'm getting "NameError: name 'foo' is not defined," since foo is > not defined in this scope. (The function works beautifully when I'm > dealing with global variables, which is very rarely). > > Any way around this?
Eh, yes, but it's getting uglier... def debug(foo): print foo, 'is:' frame = sys._getframe(-1) exec 'pprint.pprint(%s)' % foo, frame.f_globals, frame.f_locals Untested. Reinhold -- http://mail.python.org/mailman/listinfo/python-list