On Thu, 24 Mar 2005 06:39:47 -0800, Brano Zarnovican wrote:
Hi David !
I cannot see anything wrong on your code. So, I'm posting my working
example.
Hint: try to determine, why it is returning NULL (the PyErr_Print()
call)
BranoZ
OK your example works fine. I inserted it in the original code:
int
main(int argc, char *argv[])
{
PyObject *pName, *s, *pModule, *pDict, *pFunc;
PyObject *pArgs, *pValue;
int i;
if (argc < 3) {
fprintf(stderr,"Usage: call pythonfile funcname [args]\n");
return 1;
}
Py_Initialize();
pName = PyString_FromString(argv[1]);
pModule = PyImport_Import(pName);
if (pModule == NULL) {
printf( "import went bang...\n");
PyErr_Print();
return -1;
}
....
}
Te test script (again cut and pasted from the python site example) is just
this:
def multiply(a,b):
print "Will compute", a, "times", b
c = 0
for i in range(0, a):
c = c + b
return c
Calling the program gives an error;
"david@palmer:~/source/python> ./test_String script1.py multiply 4 5
import went bang...
ImportError: No module named script1.py"
script1.py exists and it is in the same directory as the executable so its
not a path error or that kind of stuff.
wierd. does:
http://www.python.org/doc/2.3.2/ext/pure-embedding.html work
for you ?
David