Skip to content

Commit 7793074

Browse files
committed
- updated hellotest.c for python2
1 parent d96ef9b commit 7793074

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

hellotest/hellotest.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
#include <Python.h>
22

3+
#if PY_MAJOR_VERSION >= 3
4+
#define PY3VER
5+
#endif
6+
37
static PyObject* hello(PyObject* self, PyObject* args) {
4-
printf("Hello, World!\n");
8+
printf("Hello World\n");
59
return Py_None;
610
}
711

8-
static PyMethodDef myMethods[] = {
12+
static PyMethodDef helloMethods[] = {
913
{ "helloworld", hello, METH_NOARGS, "Prints Hello World" },
1014
{ NULL, NULL, 0, NULL }
1115
};
1216

17+
#ifdef PY3VER
1318

1419
static struct PyModuleDef hellotest = {
1520
PyModuleDef_HEAD_INIT,
1621
"hellotest",
1722
"Hello Test Module",
1823
-1,
19-
myMethods
24+
helloMethods
2025
};
2126

2227
PyMODINIT_FUNC PyInit_hellotest(void) {
2328
return PyModule_Create(&hellotest);
2429
}
2530

31+
#else
32+
33+
// module initializer for python2
34+
PyMODINIT_FUNC inithellotest() {
35+
Py_InitModule3("hellotest", helloMethods, "Hello Test Module");
36+
}
37+
38+
#endif
39+
2640

0 commit comments

Comments
 (0)