Embedded Python: Module über das Netzwerk laden
-
Hoi!
Ich habe eine Applikation, die eine in C++ und Boost.Python eine API bereitstellt und den Python Interpreter einbindet (embedded).
Jetzt möchte ich gerne bei Bedarf über das Netzwerk Module nachladen ohne sie davor auf der Festplatte speichern zu müssen.
Ich könnte zwar die Daten einfach in Textform downloaden und durch boost::python::exec jagen, dann hab ich sie allerdings im Hauptnamensraum, was ich vermeiden möchte ...
Hier einfach mal Code.Der Interpreter:
void INTERNAL_API PythonThread() { try { // Make Acid loadable. PyImport_AppendInittab("Acid", &initAcid); // Initialize the Python interpreter. Py_Initialize(); // Import the main module. boost::python::object mainModule(boost::python::import("__main__")); // Get the main namespace. boost::python::object mainNamespace(mainModule.attr("__dict__")); // Import the PythonAcid module. boost::python::object acid(boost::python::import("Acid")); mainNamespace["Acid"] = acid; // Run the initial code. boost::python::object dummy(boost::python::exec( GlobInitialCode.c_str(), mainNamespace)); } catch(boost::python::error_already_set const&) { std::cout << Acid::translatePythonError() << std::endl; } catch(std::exception const& e) { std::cout << e.what() << std::endl; } }
Wie könnte ich jetzt ohne ein import-Statement ein Modul holen?
Danke schon mal!
Grüße,
Ethon