Created
December 15, 2015 04:17
-
-
Save bukzor/e176d397546519c09bd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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