[Tutor] printing variable name and value?
Emile van Sebille
emile@fenx.com
Wed, 31 May 2000 17:46:02 -0700
Oops, last part of the last line ended up
on the cutting room floor as I cut the
comments out... s/b
def showvars(*vars):
import sys
try:
1/0
except ZeroDivisionError:
callers_globals = sys.exc_info()[2].tb_frame.f_back.f_globals
callers_locals = sys.exc_info()[2].tb_frame.f_back.f_locals
if id(callers_locals) == id(callers_globals):
callers_globals = {}
varids=[]
for eachvar in vars:
varids.append(id(eachvar))
#found, tofind = 0, len(varids)
for calling_var_name, calling_var_value in callers_locals.items() +
callers_globals.items():
if id(calling_var_value) in varids:
print calling_var_name, " = ", calling_var_value
#found = found + 1
#if found == tofind:
#break
Emile van Sebille
emile@fenx.com
-------------------