2

so.. let's say i have this C function:

PyObject* Foo(PyObject* pSelf, PyObject* pArgs)
{
    MessageBox(NULL, "Foo was called!", "Info", MB_OK);
    return PyInt_FromLong(0);
}

and then, I have to do this:

static PyMethodDef Methods[] = 
{
    {"Foo", Foo, METH_NOARGS, "Dummy function"},
    {NULL, NULL, 0, NULL}
};
Py_InitModule("bar", Methods);

and I execute my python script.. but C functions are a little annoying, it's C++ and I use classes for almost everything.

So, is there any way to import member functions from a class to my python script?

oh btw, the python script looks something like this:

import bar
from bar import *
Foo()

4 Answers 4

5

boost.python enables you to do that very effectively.

Sign up to request clarification or add additional context in comments.

Comments

2

SWIG would work pretty well, too.

Comments

1

Take a look at boost python page. Search for 'free function'.

Comments

0

Cython has the best C++ wrapping I have found, even though it is a bit more verbose than SWIG and it is a bit of a mindset to get into. It's easier to write mappings than SWIG -- because it uses Python types -- but you have to write them all by hand. It's also a very active project with a very friendly mailing list. It also has good buffer support for NumPy.

Comments

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.