What is the equivalence of python type (<name>, <base>, <dict>) "in C ++?

Ok, I embed python 3.3 in a C ++ application. I want to dynamically create a python class on the C ++ side in the same way as if I were doing the following in python:

my_type = type("MyType", (object,), dict())

I know that I can always import the "inline" module, but I try to avoid importing on the C ++ side in general.

Thank!

+4
source share
1 answer

Everything seems to work fine:

PyObject *type(const char *name, boost::python::tuple bases, boost::python::dict dict) {
    return PyType_Type.tp_new(&PyType_Type,
        Py_BuildValue("sOO", name, bases.ptr(), dict.ptr()), NULL);
}

Thanks to Zack for pointing me in the right direction!

+1
source

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


All Articles