Last active
June 21, 2021 06:18
-
-
Save lezwon/671f7986619e6ed14d21299bc6b9531d 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> | |
#include <string.h> | |
static PyObject* name(PyObject *self, PyObject* args){ | |
char *name; | |
char greeting[255] = "Hello "; | |
if (!PyArg_ParseTuple(args, "s", &name)){ | |
return NULL; | |
} | |
strcat(greeting, name); | |
return Py_BuildValue("s", greeting); | |
} | |
static PyMethodDef moduleMethods[] = { | |
{"name", name, METH_VARARGS, "Greets with your name"} | |
}; | |
static struct PyModuleDef greetModule = { | |
PyModuleDef_HEAD_INIT, | |
"greet", | |
"Greetings Module", | |
-1, | |
moduleMethods | |
}; | |
PyMODINIT_FUNC PyInit_greet(void){ | |
return PyModule_Create(&greetModule); | |
}; |
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
import load_images | |
import timeit | |
import greet | |
print("Name: ", greet.__name__) | |
print("Docstring: ", greet.__doc__) | |
print("Greeting: ", greet.name("Lezwon")) |
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
from setuptools import setup, Extension | |
ext_modules = [ | |
Extension('greet', sources = ['greetmodule.c']), | |
] | |
setup( | |
name = 'Greeting Project', | |
ext_modules = ext_modules | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment