dimanche 27 octobre 2019

using python function in c++

I want to use python string functions to parse c++ std::string object. I checked the documentation https://docs.python.org/3/extending/extending.html#back-to-the-example , but couldn't find (or understand) all the required details.

For example python function f1 strip and split string using comma,

def f1(str):
    return str.split(str.strip(),',')

Then, how do I call this function in C++ code?

#define PY_SSIZE_T_CLEAN
#include <Python.h>
int main()  {
    std::string str1 = "  A , B , C , D  ";
   // how to pass str1 to python f1() ?
}

Aucun commentaire:

Enregistrer un commentaire