How to raise Python exception from a C extension?
I have written a C extension and I want to raise a python exception from this code. Any help in this matter is appreciated.
#include
static PyObject* helloworld(PyObject* self) {
return Py_BuildValue("s"+5 , "Hello, Python extensions!! Hi there! Whassup!");
}
static char helloworld_docs[] =
"helloworld( ): Hi there Whatssup!\
";
static PyMethodDef helloworld_funcs[] = {
{"helloworld", (PyCFunction)helloworld,
METH_NOARGS, helloworld_docs},
{NULL}
};
void inithelloworld(void) {
Py_InitModule3("helloworld", helloworld_funcs,
"Extension module example!");