Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Wishlist: Reset interpreter
-
I Would like to have a Button that Resets the Python Interpreter into the State that it has when the Application is launched . Use Case: when developing a Module, it is difficult to convince Python to reload changed module sources. Reset Would make this easy and Would also be a way to get Pythonista into a well defined State in Case of Other Problems. Currently, this requiries killing pythonista from iOS, which is a bit annoying.
Georg -
import my_module ; reload(my_module) # Pythonista workaround
-
Yes, I use the reload all the time. Under 1.5 , I found even with the reload(module), I often had to run twice before the changes of the imported module would take effect. Which is fine. Better than quitting Pythonista. Haven't tried it in 1.6 yet
-
@ccc I know! But a reset is even better... It helps with monkey-patched methods, misconfigured globals, and a lot more circumstances that can make a running Python interpreter behave weird.
Georg -
This is going to sound stupid, but is there anyway to have python to run a pre and post script when executing a script? Globally, I mean.
I am guessing not, but if it was possible could possibly provide a solution here as well to other issues also. -
i wonder if it would be possible to pickle sys.modules in a clean session, then load it again when you want to reset. Alternatively, store a list of modules that are loaded at start, and then resetting the interpreter would consist of deleting any modules that don not belong, and maybe reloading any modules which do.
for m in sys.modules.keys() if not m in oldmodules: del sys.modules(m)
-
@Phuket2 you can create your own action menu item which does what you say. I have an action menu to run a script in the same interpreter ( without clearing globals) because i find that easier for debugging. You could add some lines before/after the execfile.
# execute script in editor, in current interpreter session without clearing globals import editor,os file=editor.get_path() os.chdir(os.path.dirname(file)) execfile(file)