|
Boost : |
From: Gao Yang (gaoyang_at_[hidden])
Date: 2004-07-13 02:46:00
Hi,
I am having problem when running the following c++ code. The system
tells me "Unhandled exception ....":
(I also tried running PyRun_String with the string identical to
strings in hello.py, and it worked fine.)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <boost/python.hpp>
#include <iostream>
using namespace boost::python;
int main ()
{
Py_Initialize ();
object main_module (handle<> (borrowed (PyImport_AddModule("__main__"))));
object main_namespace = main_module.attr ("__dict__");
std::string filename = "hello.py";
FILE *fp = fopen( filename.c_str(), "r" );
if (fp == NULL)
{
std::cerr << "failed to open file" << std::endl;
return -1;
}
handle<> (PyRun_File (
fp
, const_cast<char*>(filename.c_str())
, Py_file_input
, main_namespace.ptr()
, main_namespace.ptr()));
fclose(fp);
Py_Finalize ();
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
(Here is the content of hello.py:)
####################
hello = file('hello.txt', 'w')
hello.write('Hello world!')
hello.close()
####################
Can anyone point me what do I need to get it running. Thanks very much!
Regards, Gao Yang
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk