Run python object in C ++

I only have a question about running a python object in C ++. Let me explain what I want to do in the following example.

int main () {
    // as you know, the python object has its member variables etc, and 
    // I want it to be initialized only once
    py = python_object();   
    while (1) {
        // here, I am hoping to call a member function from the object continously
        // and get a return value. 
        int abc = py.get_num(); 
        if (abc < 0) break;
        do_something_in_my_cpp_code();
    }


}

The python object I talked about here is oOjbect Capture .

I wonder how difficult it would be if you have experience with such things. I am also open to other possible methods, such as the opposite (running a C ++ object inside a python script). Thank!

+4
source share
1 answer

solution 1 create a small python script that calls your function and prints the result. then in a c ++ program use popen to call the python script and get the displayed value.

2 python ++ https://docs.python.org/2/extending/embedding.html

python, , 1 .

0

Source: https://habr.com/ru/post/1683283/


All Articles