From e33da01ae8155f3a5488d1620f0393fed79364e9 Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Fri, 15 Nov 2019 11:21:36 +0100 Subject: [PATCH] port code that we directly feed into the Python interpreter from C++ --- modules/gui/src/gosty.cc | 14 +++++++++----- modules/gui/src/python_shell/python_interpreter.cc | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/gui/src/gosty.cc b/modules/gui/src/gosty.cc index b5275bb3e..350b1f520 100644 --- a/modules/gui/src/gosty.cc +++ b/modules/gui/src/gosty.cc @@ -185,14 +185,18 @@ int init_python_interpreter() String python_loc=setup_python_search_path(root, py); //py.RunCommand("from ost import *"); //py.RunCommand("gui_mode=True"); - std::stringstream cmd; - cmd << "execfile('" << python_loc; + std::stringstream script_path; + script_path << python_loc; #ifdef _MSC_VER - cmd << "\\ost\\gui\\"; + script_path << "\\ost\\gui\\"; #else - cmd << "/ost/gui/"; + script_path << "/ost/gui/"; #endif - cmd << "gosty_startup.py')"; + script_path << "gosty_startup.py"; + + std::stringstream cmd; + cmd << "exec(compile(open('" << script_path.str() << "').read(),'"; + cmd << script_path.str() << "', 'exec'))"; py.RunCommand(QString::fromStdString(cmd.str())); return 0; } diff --git a/modules/gui/src/python_shell/python_interpreter.cc b/modules/gui/src/python_shell/python_interpreter.cc index 29178f2c0..08b0c3471 100644 --- a/modules/gui/src/python_shell/python_interpreter.cc +++ b/modules/gui/src/python_shell/python_interpreter.cc @@ -54,7 +54,7 @@ PythonInterpreter::PythonInterpreter(): main_module_ = bp::import("__main__"); main_namespace_ = bp::extract<bp::dict>(main_module_.attr("__dict__")); main_namespace_["os"]=bp::import("os"); - main_namespace_["__builtin__"]=bp::import("__builtin__"); + main_namespace_["builtins"]=bp::import("builtins"); main_namespace_["keyword"]=bp::import("keyword"); bp::object code=bp::import("code"); compile_command_=code.attr("compile_command"); -- GitLab