Executing script with embedded python

Andrew Ayre andy at nospam.com
Wed Jan 25 18:10:38 EST 2006


Hi, I have a script that I want to execute from C. I don't want to call any
functions, just execute the script. Below is a code snippet.

The problem is that PyObject_CallObject always returns NULL. Is this the
correct return value for simply executing a script, as there is no function
return value involved?

  // load script
  pname = PyString_FromString(SCRIPTFILENAME);
  pmodule = PyImport_Import(pname);
  Py_DECREF(pname);

  if (pmodule != NULL)
  {
    // execute script
    presult = PyObject_CallObject(pmodule, NULL);
    if (presult == NULL)
    {
      Py_DECREF(pmodule);
      return;
    }
    Py_DECREF(presult);
    Py_DECREF(pmodule);
  }
  else
  {
    return;
  }


regards, Andy
andy at britishideas1965.com (remove year to reply)





More information about the Python-list mailing list