embedded python example: PyString_FromString doesnt work?

David Harris david at palmernet.net
Fri Mar 25 04:52:09 EST 2005


On Fri, 25 Mar 2005 11:09:35 +0300, Denis S. Otkidach wrote:

> DH> Calling the program gives an error;
> DH> "david at palmer:~/source/python> ./test_String script1.py  multiply 4
> DH> 5 import went bang...
> DH> ImportError: No module named script1.py"
> DH> script1.py exists and it is in the same directory as the executable
> DH> so its not a path error or that kind of stuff.
> 
> I believe you have to call Py_SetProgramName before Py_Initialize, or
> otherwise let Python know that it should look for modules in this
> directory. See http://python.org/doc/current/api/embedding.html#l2h-40

excellent!! that was the tip (+ "PySys_SetArgv") the worked ...

This now works:

int
main(int argc, char *argv[])
{
    PyObject *pName, *s, *pModule, *pDict, *pFunc;
    PyObject *pArgs, *pValue;
    int i;

    Py_SetProgramName(argv[0]);
    Py_Initialize();
    PySys_SetArgv(argc, argv);
    pName = PyString_FromString(argv[1]);
...
}

Thanks a bunch denis :)



More information about the Python-list mailing list