With good spaces :
def runcode(srcode): import sys,traceback sret=True try: ccod=compile(srcode, 'Paul-code', 'exec') flagcompile=True except: print "compilo-error" flagcompile=False if flagcompile==True: try: exec(ccod,globals(),globals()) sret=True except: tb=sys.exc_info()[2] #for traceback print str(sys.exc_info()[0]) print traceback.format_exc() sret=False return sret s="""global c a=1000 b=123 c=a+b""" if runcode(s): print c s="""global c a=1000 b=123 c=aaa+b""" if runcode(s): print c -- http://mail.python.org/mailman/listinfo/python-list