Suppose I have a Python class like so:
class MyPythonClass:
def Func1(self, param):
return
def Func2(self, strParam):
return strParam
If I want to embed the Python script that contains that class in my C++ code, create an instance of that object via my C++ code, and then call a member on that python object, how do I go about that?
I would think it would be something like this:
namespace python = boost::python;
python::object main = python::import("main");
python::object mainNamespace = main.attr("__dict__");
python::object script = python::exec_file(path_to_my_script, mainNamespace);
python::object foo = mainNamespace.attr("MyPythonClass")();
python::str func2return = foo.attr("Func2")("hola");
assert(func2return == "hola");
But the many variations of this code I have tried have not worked. What is the magic sauce I need to pour over my code to be able to do this?