0

I've followed this video tutorial on setting up a very basic C++ extension for python using Visual Studio. It's very straightforward and works quite nicely. https://www.youtube.com/watch?v=y_eh00oE5rI

Here's what my code looks like.

#ifdef _DEBUG
#define _DEBUG_WAS_DEFINED
#undef _DEBUG
#endif

#include <Python.h>

#define MODULE_NAME "DummyExt"

PyObject* greet(PyObject* self, PyObject* args)
{
    return PyString_FromString("Hello world!");
}

PyMethodDef DummyExtMethods[] = 
{
    {"greet", greet, METH_NOARGS, nullptr}
};

PyMODINIT_FUNC
initDummyExt(void)
{
    PyObject* m;
    m = Py_InitModule(MODULE_NAME, DummyExtMethods);
    if (m == nullptr)
    {
        return;
    }
}


#ifdef _DEBUG_WAS_DEFINED
#define _DEBUG 1
#endif

How can I use python's APIs to expose C++ classes from an extension? I want to be able to define my class and its logic in C++ and be able to instantiate it from python and call its member functions and whatnot. As the title says I don't want to use any 3rd party tools and such, only the headers and libs that come with python.

Any help would be appreciated :)

2
  • Please disregard this question. After reading up more on python's APIs, without a 3rd party tool, this will be far too gargantuan of an undertaking and I've given up on going this route. Commented Nov 2, 2016 at 11:17
  • You can delete the question Commented Nov 20, 2016 at 12:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.