How to make functions available in the "Python/C API"?

Asked

Viewed 42 times

0

hello I am developing a python module and I have the following problem. When the module is compiled, only one function is available (fun1). how do I get fun2 stay available too?

#define PY_SSIZE_T_CLEAN
#include <Python.h>


static PyObject* spam_fun2(PyObject *self) 
{
    # codigos
    return Py_None;
}

static PyObject* spam_fun1(PyObject *self) 
{
    # codigos
    return Py_None;
}

static struct PyModuleDef spammethods[] = {
    { "fun1", spam_fun1, METH_NOARGS, " " },
    { "fun2", spam_fun2, METH_NOARGS, " " },
    { NULL, NULL, 0, NULL }
};

static struct PyModuleDef spammodule = {
    PyModuleDef_HEAD_INIT,
    "spam",
    "Lib exe command",
    -1,
    spammethods
};

PyMODINIT_FUNC PyInit_spam()
{
    return PyModule_Create(&spammodule);
}

compiling:

from distutils.core import setup
from distutils.core import Extension


setup(
    name='spam',
    version='1.0',
    ext_modules=[Extension('spam', ['spam.c'])]
)
  • 1

    How you compiled and tested the code?

  • there I edited the question

  • Tips: avoid spelling mistakes, always make intuitive titles so that the question is easily found by people with similar problems.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.