Sign in to follow this  
lettel

Python Interpreter ?

Recommended Posts

I am looking for a built in command for the python interepter that is similar to the Matlab command 'clear', something that will reset the state of the interpreter without exiting the interpreter. I assume on exists but I am a beginner so I am not familiar with the python lingo and so I am having troubles finding one.

Share this post


Link to post
Share on other sites
AFAIK, there is no way to reasonable way to reset python. It wasn't designed for such a situation. Suggesting an approach will depend a little on what you're trying to achieve, and how much 'state' you really need to reset. If you're running idle, it may be sufficient to save your code into a file and re-run it each time.

Rather than storing your variables and functions as globals you could also just store them in a dictionary which could be cleared when required.

The previous approach can be automated with the use ofcompile, exec* and eval functions to dynamically build and run code. These functions give you the choice to pass in a dictionary containing variables. Instead of using the default value of locals and globals you can setup a dictionary that contains your 'global' variables and functions which will be visible to your script.

I'm more than willing to post some code examples if you think that will help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this