Maybe inspect
will help you, but then you need to filter out the information.
Using:
> import inspect > a = 5 > f = inspect.currentframe() > print f.f_locals ... ... 'a': 5 ...
It might be worth mentioning that you cannot iterate over the resulting dictionary in a for
loop, because binding to a variable will change that dictionary. You should only iterate over the keys (at least what I just found out).
Example:
for v in f.f_locals.keys(): if not v.startswith("_"): print v
Look at the first line: just writing for v in f.f_locals
will fail.
source share