📄 hello.c
字号:
#include <Python.h>
#include <string.h>
/**//* module functions */
static PyObject * /**//* returns object */
message(PyObject *self, PyObject *args) /**//* self unused in modules */
...{ /**//* args from Python call */
char *fromPython, result[64];
if (! PyArg_Parse(args, "(s)", &fromPython)) /**//* convert Python -> C */
return NULL; /**//* null=raise exception */
else ...{
strcpy(result, "Hello, "); /**//* build up C string */
strcat(result, fromPython); /**//* add passed Python string */
return Py_BuildValue("s", result); /**//* convert C -> Python */
}
}
/**//* registration table */
static struct PyMethodDef hello_methods[] = ...{
...{"message", message, 1}, /**//* method name, C func ptr, always-tuple */
...{NULL, NULL} /**//* end of table marker */
};
/**//* module initializer */
void inithello( ) /**//* called on first import */
...{ /**//* name matters if loaded dynamically */
(void) Py_InitModule("hello", hello_methods); /**//* mod name, table ptr */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -