Skip to content

Instantly share code, notes, and snippets.

@SirmaXX
Last active May 23, 2021 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirmaXX/70650a47ccee169efe1eee7708fe70ea to your computer and use it in GitHub Desktop.
Save SirmaXX/70650a47ccee169efe1eee7708fe70ea to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <Python.h>
int addition (int a, int b) {
return a+b;
}
// sum of two number
static PyObject* DemoLib_addition(PyObject *self, PyObject *args) {
int a;
int b;
if (!PyArg_ParseTuple(args, "ii", &a, &b)) {
return NULL;
}
return Py_BuildValue("i", addition(a,b));
}
// module's function table
static PyMethodDef demoMethods[] ={
{"addition", DemoLib_addition, METH_VARARGS, "sum of two number"},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef demomodule = {
PyModuleDef_HEAD_INIT,
"demo",
NULL,
-1,
demoMethods
};
PyMODINIT_FUNC
PyInit_demo(void)
{
Py_Initialize();
return PyModule_Create(&demomodule);
}
import demo
# kütüphane yükleyelim
a,b=int(input()),int(input())
result=addition(a,b)
print("toplam ",result)
from setuptools import Extension, setup
module = Extension("demo",
sources=[
'demo.c'
])
setup(name='demo',
version='1.0',
description='example demo package',
ext_modules=[module])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment