在Python C API中,为什么包装函数是静态的

2 c python python-c-api

所以我有下面用C扩展python的示例代码

#include <python.h>

static PyObject* sayhello(PyObject* self, PyObject *args) {
   const char* name;

   if (!PyArg_ParseTuple(arg, "s", &name))
       return NULL;

    printf("Hello %s !\n", name);

    Py_RETURN_NONE;
}

static PyMethodDef HelloMethods[] = 
{
    {"say_hello", say_hello, METH_VARARGS, "Greet Somebody."},
    {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC inithello(void) {
    (void) Py_InitModule("hello", HelloMethods);
}
Run Code Online (Sandbox Code Playgroud)

而我的问题是为什么下面的包装函数静态

   static PyObject* sayhello(PyObject* self, PyObject *args) {
Run Code Online (Sandbox Code Playgroud)

DrC*_*DrC 5

如果不需要在源文件之外通过名称引用/链接C中的函数,则可以将其保持为静态.在这种情况下,Python链接是使用源文件中的引用完成的,因此不需要外部链接.如果函数是外部可见的,但为什么污染你的名字空间,代码也可以正常工作?