PyImport_Import() failed

Yang Fan missdeer at gmail.com
Wed Aug 2 13:09:02 EDT 2006


Hello,
   I'm new to Python.I want to embed Python interpreter into my C++
application powered by Borland C++ Builder 2006.
   I have written some C++ code in order to evaluate Python script file, but
PyImport_Import() calls failed.I really don't know what's wrong with my cpp
code.It always return a NULL value.
   Any advice is appreciated!


int TPython::ExecuteScript(const char * pszFileName)
{

        PyObject *pFileName, *pModule, *pDict, *pFunc;
        PyObject *pArgs, *pValue;

        pFileName = PyString_FromString(pszFileName);
        /* Error checking of pFileName left out */
        if(!pFileName)
        {
                trace1(("pFileName == NULL "));
        }

        pModule = PyImport_Import(pFileName);     // always failed, returned
NULL:(
        Py_DECREF(pFileName);

        if (pModule != NULL)
        {
           ................
        }
        else
        {
            PyErr_Print();
            trace1(("Failed to load \"%s\"\n", pszFileName));
            return 1;
        }

        return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060803/f258046f/attachment.html>


More information about the Python-list mailing list