你可以从C码中进口on素模块,把像你那样用平典法界定的物品称作。 这是一个远大的节奏,但完全有可能。
当我想研究如何做像我这样的事情时,请参阅 进口模块将有所帮助。 你们还需要读一下,如何读写的是特性、称呼功能等等。
然而,我怀疑你真的想要做的是:underlying Library sdl from C. 这是一个Clibrary,从C.真正容易使用。
这里有一些样本代码,以进口C版的假装模块,该模块根据工作守则的参数进行调整。
PyObject *module = 0;
PyObject *result = 0;
PyObject *module_dict = 0;
PyObject *func = 0;
module = PyImport_ImportModule((char *)"pygame"); /* new ref */
if (module == 0)
{
PyErr_Print();
log("Couldn t find python module pygame");
goto out;
}
module_dict = PyModule_GetDict(module); /* borrowed */
if (module_dict == 0)
{
PyErr_Print();
log("Couldn t find read python module pygame");
goto out;
}
func = PyDict_GetItemString(module_dict, "pygame_function"); /* borrowed */
if (func == 0)
{
PyErr_Print();
log("Couldn t find pygame.pygame_function");
goto out;
}
result = PyEval_CallObject(func, NULL); /* new ref */
if (result == 0)
{
PyErr_Print();
log("Couldn t run pygame.pygame_function");
goto out;
}
/* do stuff with result */
out:;
Py_XDECREF(result);
Py_XDECREF(module);