[C++-sig] Re: compile errors with embedding example from tutorial

Joel de Guzman joel at boost-consulting.com
Fri Jul 2 08:57:27 CEST 2004


Faheem Mitha wrote:

> However, I still cannot get a Python extension module with the
> interpreter imbedded to work, however. I still get the same error as
> before.

Hi Faheem,

The code in the tutorial can be found in the test/embedding.cpp/py
You can find a function called test_tutorial() there:

void
test_tutorial()
{
     using namespace boost::python;

     object main_module(
         handle<>(borrowed(PyImport_AddModule("__main__"))));

     object main_namespace = main_module.attr("__dict__");

     handle<>(PyRun_String(

         "hello = file('hello.txt', 'w')\n"
         "hello.write('Hello world!')\n"
         "hello.close()"

       , Py_file_input
       , main_namespace.ptr()
       , main_namespace.ptr())
     );
}

AFAIK, the code is passing the regression tests. Perhaps you can use
the test example as a staring point?

HTH,
-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net




More information about the Cplusplus-sig mailing list