Skip to content

Instantly share code, notes, and snippets.

@bukzor
Created December 15, 2015 04:17
Show Gist options
  • Save bukzor/e176d397546519c09bd3 to your computer and use it in GitHub Desktop.
Save bukzor/e176d397546519c09bd3 to your computer and use it in GitHub Desktop.
#include <Python.h>
static PyObject* _hello_world(PyObject* self) {
PyObject_Print(PyUnicode_FromString("hello world\n"), stdout, Py_PRINT_RAW);
return Py_None;
}
static struct PyMethodDef methods[] = {
{"hello_world", (PyCFunction)_hello_world, METH_NOARGS},
{NULL, NULL}
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef module = {
PyModuleDef_HEAD_INIT,
"project_with_c",
NULL,
-1,
methods
};
PyMODINIT_FUNC PyInit_project_with_c(void) {
return PyModule_Create(&module);
}
#else
PyMODINIT_FUNC initproject_with_c(void) {
Py_InitModule3("project_with_c", methods, NULL);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment