On Fri, 02 Jul 2004 14:57:27 +0800, Joel de Guzman <joel@boost-consulting.com> wrote:
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?
Thanks. However, I am not sure which version of the test/embedding.cpp you are referring to. The version at http://www.boost.org/libs/python/test/embedding.cpp which I assume is the current CVS, is the same as the version in 1.31, and neither of them have the code you refer to. In any case, does the code you refer to define an extension module which embeds the interpreter and can be called from Python? Because that is the case I am interested in. I have been unable to find any examples out there along these lines, despite some effort. The current version of test/embedding.cpp that I have seen is a C++ executable, and the extension module defined there is called within the interpreter that is embedded in this executable. This is not the same as what I am trying to do. Faheem.