0

I'm looking for a way how to create an instance of a class written in python and call it's methods from c++. If available, I'd prefer to incldue the boost python libraries. I imagine to have a class in python like

class MyPythonClass(object):
    def __init__(self, first_var):
        self.__varToStore = first_var
    def method_to_call(self, list_of_input = []):
        ### some manipulation
        return 42

I've already found lot's of threads, how to import the python module in c++ using the python libraries and may-be I've found a way how to create an instance of the class.

boost::python::object mylib = boost::python::import("MyModule");
boost::python::object my_class = mylib.attr("MyPythonClass");

But from that point, I'm just stuck. How can I create an instance of the class and call its method?

Thanks

  • I'm not to familiar with `boost::python`, but have you taken a look at the [references manuals](http://www.boost.org/doc/libs/1_65_1/libs/python/doc/html/reference/index.html)? – Christian Dean Jan 08 '18 at 18:10
  • Yeah, I've already looked through the documentation, but I could not extract some useful information thus far. I'm also thankful if you have a minimal working example using the python libraries only. – Johannes Junggeburth Jan 08 '18 at 18:20

0 Answers0