Skip to main content
gamedev.net
🔒 Locked

Python Interpreter ?

Started by lettel 0 replies 450+ views
Original Post
lettel
lettel
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.
XXX_Andrew_XXX
XXX_Andrew_XXX
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.