I need to have my Python program access my C functions. So I used the example from the documentation to get started.
Unfortunately, its very slow and it takes up all of my memory.
I am using Windows 7 64bit, Python 3.4 and gcc (rubenvb-4.8.0) 4.8.0.
For completeness sake, here's the code from the documentation:
#include <Python.h>
static int numargs=0;
static PyObject*
emb_numargs(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":numargs"))
return NULL;
return PyLong_FromLong(numargs);
}
static PyMethodDef EmbMethods[] = {
{"numargs", emb_numargs, METH_VARARGS,
"Return the number of arguments received by the process."},
{NULL, NULL, 0, NULL}
};
static PyModuleDef EmbModule = {
PyModuleDef_HEAD_INIT, "emb", NULL, -1, EmbMethods,
NULL, NULL, NULL, NULL
};
static PyObject*
PyInit_emb(void)
{
return PyModule_Create(&EmbModule);
}
int main()
{
[...]
numargs = argc;
PyImport_AppendInittab("emb", &PyInit_emb);
Py_Initialize();
pModule = PyImport_Import(pName);
[...]
}
The python program has the following code:
import emb
print("Number of arguments", emb.numargs())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.