Created
March 8, 2015 21:32
-
-
Save jadient/e00605b331814b3fea9a to your computer and use it in GitHub Desktop.
python open interactive console (for debugging) from Tomasz Ducin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Console module provide `copen` method for opening interactive python shell in | |
the runtime. | |
http://sys-exit.blogspot.com/2013/12/python-open-interactive-console.html | |
Usage: | |
import console | |
console.copen(globals(), locals()) | |
""" | |
import code | |
import readline | |
import rlcompleter | |
def copen(_globals, _locals): | |
""" | |
Opens interactive console with current execution state. | |
Call it with: `console.open(globals(), locals())` | |
""" | |
context = _globals.copy() | |
context.update(_locals) | |
readline.set_completer(rlcompleter.Completer(context).complete) | |
readline.parse_and_bind("tab: complete") | |
shell = code.InteractiveConsole(context) | |
print "Entering console, press Ctrl-D to exit" | |
shell.interact() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment