1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include "Python.h"
static PyObject *
test(PyObject *self, PyObject *args)
{
int i, n, ran;
PyObject *list = PyList_New(0);
if (!PyArg_ParseTuple(args, "i", &n))
return NULL;
if (n < 1)
return Py_None;
//srand((int)time(NULL));
for (i=0; i<n; i++) {
ran = rand() % 100;
PyList_Append(list, PyInt_FromLong(ran));
}
return list;
}
static PyMethodDef example_methods[] = {
{"test", test, METH_VARARGS, "Retourne une liste"},
{NULL, NULL}
};
PyMODINIT_FUNC
initexample(void)
{
Py_InitModule("example", example_methods);
} |
Partager