Вопрос

i written small code like addition for two numbers in python.

addition.py
  def add(a,b):
       c=a+b
       print "result is...",c


mainpgm.c
 ???

how to call the addition.py/add function in the C(mainpgm) program.

Already i saw some links but i am not to getting clear.

Any suggestions to call the function in c.

Это было полезно?

Решение

Reading the Python manual,

#include <Python.h>

int main(int argc, char *argv[])
{
  Py_SetProgramName(argv[0]);  /* optional but recommended */
  Py_Initialize();
  PyRun_SimpleString("import addition\naddition.add(42, 42)\n");
  Py_Finalize();
  return 0;
}

might do what you want.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top