Skip to content

Instantly share code, notes, and snippets.



Last active Feb 9, 2021
What would you like to do?
Python script opening interactive console with current interpreter state. Thanks to readline/rlcompleter, you may use up/down arrows (history browse) or left/right arrows (line edition), see
Console module provide `copen` method for opening interactive python shell in
the runtime.
import code
import readline
import rlcompleter
def copen(_globals, _locals):
Opens interactive console with current execution state.
Call it with: `, locals())`
context = _globals.copy()
readline.parse_and_bind("tab: complete")
shell = code.InteractiveConsole(context)
import console
example_list = [1, 2, 3]
example_tuple = ('abc', 'def')
console.copen(globals(), locals())
print 'this will be continued'

This comment has been minimized.

Copy link
Owner Author

@ducin ducin commented Oct 8, 2013

After cloning this gist, run


in the console and type dir() to see that all modules, variables etc. are available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment