, - , line frame ( traceit ).
import re
from types import *
def interpolatevar(matchobj):
excludetypes = set((NoneType, TypeType, FunctionType, LambdaType, ClassType,
CodeType, InstanceType, MethodType, BuiltinFunctionType,
BuiltinMethodType))
var = matchobj.group(0)
basevar = var.split(".")[0]
if basevar in frame.f_code.co_names or basevar in frame.f_code.co_varnames:
if basevar in frame.f_globals or basevar in frame.f_locals:
val = eval(var, frame.f_globals, frame.f_locals)
if type(val) not in excludetypes:
return repr(val)
return var
line = re.sub(r"[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*",
interpolatevar, line)
, , , .
(, foo.bar ), , , , foo <function foo at 0x02793470> doesn ' , . ( , , types.)
, , - , , . ast , , , , .