on master help sign in
Force loading the readline module in python.

This makes program exectuion more closely mirror exectuion in the repl. Also it makes input/raw_input works as documented where the propt is written to stdout.

commit8d04ac8545914f36dad5bd71a50f5ecc201e277b authorRob Blanckaert <basicer@basicer.com> dateMon 26 Nov 2018, 13:57 (8 years ago) parent276ca5f
2 files changed+8
languages/python2/main.go+1 languages/python3/main.go+7
languages/python2/main.go+1
@@ -15,6 +15,7 @@ type Python struct{}
1515
1616func (p Python) Open() {
1717 C.Py_Initialize()
18+ p.LoadModule("readline")
1819 p.Eval("import signal")
1920 p.Eval("signal.signal(signal.SIGINT, signal.default_int_handler)")
2021}
languages/python3/main.go+7
@@ -16,6 +16,7 @@ type Python struct{}
1616
1717func (p Python) Open() {
1818 C.Py_Initialize()
19+ p.LoadModule("readline")
1920 p.Eval("import signal")
2021 p.Eval("signal.signal(signal.SIGINT, signal.default_int_handler)")
2122}
@@ -60,6 +61,12 @@ func (p Python) REPLLikeEval(code string) {
6061 C.pry_eval(ccode, C.Py_single_input)
6162}
6263
64+func (p Python) LoadModule(mod string) {
65+ cmode := C.CString(mod)
66+ defer C.free(unsafe.Pointer(cmode))
67+ C.PyImport_ImportModule(cmode)
68+}
69+
6370func (p Python) REPL() {
6471 C.pymain_run_interactive_hook()
6572