Skip to content

Instantly share code, notes, and snippets.

@lezwon
Last active June 21, 2021 06:18
Show Gist options
  • Save lezwon/671f7986619e6ed14d21299bc6b9531d to your computer and use it in GitHub Desktop.
Save lezwon/671f7986619e6ed14d21299bc6b9531d to your computer and use it in GitHub Desktop.
#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);
};
import load_images
import timeit
import greet
print("Name: ", greet.__name__)
print("Docstring: ", greet.__doc__)
print("Greeting: ", greet.name("Lezwon"))
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