Changeset b0060a for src/Python
- Timestamp:
- Apr 23, 2021, 8:31:24 PM (5 years ago)
- Branches:
- Candidate_v1.7.0, stable
- Children:
- 3f5b0a
- Parents:
- ba49d8
- git-author:
- Frederik Heber <frederik.heber@…> (08/03/20 21:55:45)
- git-committer:
- Frederik Heber <frederik.heber@…> (04/23/21 20:31:24)
- File:
-
- 1 edited
-
src/Python/PythonScripting.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Python/PythonScripting.cpp
rba49d8 rb0060a 53 53 bool executePythonScript(const std::string &python_string, const std::string &python_scripttitle) 54 54 { 55 std::stringstream input(python_string); 56 std::stringstream buffer_import; 57 std::stringstream buffer_else; 58 // move all lines with "import" to the beginning 59 std::string current_line; 60 while(std::getline(input,current_line,'\n')){ 61 if (current_line.find("import ") != std::string::npos) 62 buffer_import << current_line << std::endl; 63 else 64 buffer_else << current_line << std::endl; 65 } 66 std::string pythonscript_import( std::istreambuf_iterator<char>(buffer_import), 67 (std::istreambuf_iterator<char>()) ); 68 std::string pythonscript_else( std::istreambuf_iterator<char>(buffer_else), 69 (std::istreambuf_iterator<char>()) ); 70 55 71 try { 56 72 #ifdef HAVE_PYTHON2 … … 67 83 boost::python::object main_namespace = main_module.attr("__dict__"); 68 84 85 boost::python::handle<> imported(( PyRun_String( pythonscript_import.c_str(), 86 Py_file_input, 87 main_namespace.ptr(), 88 main_namespace.ptr() ) )); 89 69 90 boost::python::object molecuilder_module( (boost::python::handle<>(PyImport_ImportModule("pyMoleCuilder"))) ); 70 91 main_namespace["pyMoleCuilder"] = molecuilder_module; 71 92 72 93 std::string enveloped_script("print(\"BEGIN of "+python_scripttitle+":\")\n"); 73 enveloped_script += python _string+std::string("\n");94 enveloped_script += pythonscript_else+std::string("\n"); 74 95 enveloped_script += std::string("print(\"END of "+python_scripttitle+":\")\n"); 75 96
Note:
See TracChangeset
for help on using the changeset viewer.
