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.
Reset interactive console?
-
Is there a way to fully reset the interactive console, like a
=== RESTART ===
in IDLE? The clear button only seems to clear the console output, not imports, variables, etc. So far the only other way I've found is launching an essentially empty script, but that is fairly annoying, especially when also working in another script. Am I perhaps just missing something here? -
Just long tap on the clear button
-
Doh, totally missed that. Thanks!
-
PS: Wait, that apparently just crashes the entire app on purpose, meaning that I have to restart and wait for everything to load again. It is definetely possible without killing the app, after all the environment gets reset before every script launch.
-
It was possible in version 1.4 but 1.5 replaced the reset button with the Restart button :-(
-
The reason I changed this in 1.5 is that it never worked reliably. It's simply not possible to completely reset a running Python interpreter, it can always have nasty side effects, especially with extension modules that are written in C.
You could add this script to your action menu though:
import console console.clear() def _clear_all(): import inspect import os userdir = os.path.expanduser('~/Documents') site_packages_dir = os.path.expanduser('~/Documents/site-packages') keep = set(['help', '_importcompletion', '__builtins__', '__package__', 'sys', '__name__', '__doc__', '_clear_all']) for uniquevar in [var for var in globals().copy() if var not in keep]: g = globals() var_value = g[uniquevar] try: ismod = inspect.ismodule(var_value) if ismod and var_value.__file__.startswith(userdir) and not var_value.__file__.startswith(site_packages_dir): reload(g[uniquevar]) elif ismod and var_value.__name__ == 'matplotlib.pyplot': try: var_value.clf() except: pass except: pass del g[uniquevar] _clear_all() del _clear_all
This is essentially the same as what happens when you run a (non-action) script and have the "Clear Global Variables" option enabled (the default). Additionally, it clears the console text output, but you could easily remove that if you want (delete the first two lines).