mad city wrote:
Thanks. Good advice.

 From the quickstart project, the embedded.cpp file function


void exec_file_test(std::string const &script)
{
    std::cout << "running file " << script << "..." << std::endl;
// Run a python script in an empty environment.
    python::dict global;
python::object result = python::exec_file(script.c_str(), global, global);

    // Extract an object the script stored in the global dictionary.
    BOOST_TEST(python::extract<int>(global["number"]) ==  42);
std::cout << "success!" << std::endl;
}

calls my python script file - parseLogs.py which starts with

try something like this. When you exec the file you have to supply a globals dictionary that contains whatever globals you want to use (like import)

    Py_Initialize();

    bp::object main = bp::import("__main__");
    bp::object py_ = main.attr("__dict__");
    bp::exec_file("conf.py", py_, py_);
    int = bp::extract<int>(py_["some_int_is_here"];

-t
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to