callling python function in c

Anssi Saari as at sci.fi
Tue Oct 18 07:32:15 EDT 2011


masood shaik <masood.524 at gmail.com> writes:

> Hi
>
>   I am trying to call python function from c code.The following
> program i got from the web source while i am trying to run this
> program it throws an segmentation fault.

Yes, the call to PyImport_Import fails and returns a NULL. You could use
the more complete example at
http://docs.python.org/extending/embedding.html which includes some
error handling...

Anyways, apparently PyImport_Import can't import from the current
working directory but with parameters like math sqrt 2 it returns the
square root of 2. Setting PYTHONPATH to point to the working directory
works for me, but I don't know if there's a more correct solution.



More information about the Python-list mailing list