Running autogenerated code in another python instance

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


Hi!

I did not understand anything with your chatterer message.
But, perhaps, the code below will help you.

@-salutations

Michel Claveau



 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








More information about the Python-list mailing list