19 PyObject * PythonLoader::load_module_from_file(
const std::string& fname) {
21 std::ifstream file_stream( fname.c_str() );
23 INPUT_CHECK(! file_stream.fail(),
"Can not open input file '%s'.\n", fname.c_str() );
24 file_stream.exceptions ( ifstream::failbit | ifstream::badbit );
26 std::stringstream buffer;
27 buffer << file_stream.rdbuf();
30 unsigned int pos = fname.rfind(
"/");
31 if (pos != string::npos)
32 module_name = fname.substr(pos+1);
39 return load_module_from_string(module_name, buffer.str() );
44 PyObject * PythonLoader::load_module_from_string(
const std::string& module_name,
const std::string& source_string) {
47 char * tmp_name =
new char[ module_name.size() + 2 ];
48 strcpy( tmp_name, module_name.c_str() );
49 PyObject * result = PyImport_ExecCodeModule(tmp_name,
50 Py_CompileString( source_string.c_str(),
"flow123d_python_loader", Py_file_input ) );
54 std::cerr <<
"Error: Can not load python module '" << module_name <<
"' from string:" << std::endl;
55 std::cerr << source_string << std::endl;
63 internal::PythonRunning PythonLoader::py_running;
68 PythonRunning::PythonRunning() {
74 PythonRunning::~PythonRunning() {