Thursday 15 May 2014

python - Clear the environment of the evalutor -


Can I clean the python environment, such as to bring the evaluator to the same state machine after startup?

I wish I did not restart the evalutor.

You actually have Python interpreter with Python code, though you can do it with custom C program Which embeds Python interpreter.

However, for your special case, it will probably be enough to run each of your "problems" with a sub-interpreter, with something like this ...

  Import sys Import DP Def Reset (): Increase SystemExit (123) sys.modules ['__Beltin __'] reset = reset banner = None 1: Try: code.interact (banner = banner, local = {}) Except systemExit e: if e.code == 123: banner = 'Resetting ...' Continue   

... Then when you run that script, So you use it this way Can ...

Python 2.7.4 (default, 1 April 2013, 18:28:01) [GCC 4 7.3] "Help" for more information on linux2, "Copyright "," Credit "or" license ". (Interactive Console) & gt; & Gt; & Gt; Dir () ['__builtins__'] & gt; & Gt; & Gt; A = 1 & gt; & Gt; & Gt; Dir () ['__builtins__', 'a']> gt; & Gt; & Gt; Resetting () reset ... & gt; & Gt; & Gt; Dir () ['__builtins__']

No comments:

Post a Comment