我正在尝试创建一个需要争论的Python扩展。这是我的脚本:
#include <Python.h>
static PyObject * _message(PyObject *self, PyObject *args) {
char *title, *message;
if (!PyArg_ParseTuple(args, &title, &message))
return NULL; // Throw an error
return Py_BuildValue("");
}
static PyMethodDef methods[] = {
{"Message", (PyCFunction) _message, METH_VARARGS, "Message(title, message) Take a message"},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef functions = {
PyModuleDef_HEAD_INIT,
"test",
"Take a message",
"-1",
methods
};
PyMODINIT_FUNC PyInit_test(void) {
PyObject *module = PyModule_Create(&functions);
return module;
}
Setup.py:
from setuptools import setup, Extension
module = Extension (
"test",
sources = ['test.c'])
setup(
name = "test",
version = "1.0",
description = "Take message input",
author = "Simon",
ext_modules = [module])
我非常确定我的其余代码正确无误,除了在以下位置采用参数:
static PyObject * _message(PyObject *self, PyObject *args) {
char *title, *message;
if (!PyArg_ParseTuple(args, &title, &message))
该扩展已创建,但是当我尝试运行它时,它崩溃了。
我该如何接受位置论证?
相关分类