C言語への埋め込み (2)
Pythonファイルの実行
// test.c #include "Python.h" int main(int argc, char* argv[]) { PyObject* PyFileObject; Py_Initialize(); PyFileObject = PyFile_FromString("test.py", "r"); PyRun_SimpleFile(PyFile_AsFile(PyFileObject), "test.py"); Py_Finalize(); return 0; }
# test.py def foo(): a, b = 1, 2 print a+b foo()
C:\temp\python>gcc test.c -o test -IC:\Python25\include C:\Python25\libs\python25.lib
C:\temp\python>test
3