How to embed?
Ignacio Vazquez-Abrams
ignacio at openservices.net
Sat Sep 8 17:10:29 EDT 2001
On Sat, 8 Sep 2001, Ignacio Vazquez-Abrams wrote:
> Can anyone explain why it won't find a .py file in the same directory when
> it works fine when running the same code interactively?
Okay, I've figured it out:
---
int main(int argc, char **argv)
{
PyObject *module, *dict, *foo, *result;
char *path, *newpath;
double x=5.5, y=6.6;
Py_SetProgramName(argv[0]);
Py_Initialize();
path=Py_GetPath();
newpath=strcat(path, ":.");
PySys_SetPath(newpath);
free(newpath);
module=PyImport_ImportModule("exmpl");
dict=PyModule_GetDict(module);
foo=PyDict_GetItemString(dict, "foo");
result=PyObject_CallFunction(foo, "dd", x, y);
printf("The answer is %.2f!\n", PyFloat_AsDouble(result));
Py_Finalize();
return 0;
};
---
--
Ignacio Vazquez-Abrams <ignacio at openservices.net>
More information about the Python-list
mailing list