Running autogenerated code in another python instance

Do Re Mi chel La Si Do enleverlesO.OmcO at OmclaveauO.com
Wed Nov 2 02:38:10 EST 2005


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





More information about the Python-list mailing list