import sys import re instr = sys.stdin.read() subs = [] success = False while not success: try: indict = eval(instr) success = True except NameError, e: defname = re.search("name '([^\']*)' is not defined", str(e)).group(1) subs.append(defname) locals()[defname] = '//substitute{%d}' % (len(subs) - 1) outlist = indict.items() outstr = str(outlist) for i, sub in enumerate(subs): outstr = outstr.replace("'//substitute{%d}'" % i, sub) print outstr