8 #include <boost/python.hpp>
9 #include <boost/noncopyable.hpp>
20 using namespace boost::python;
21 if (!Py_IsInitialized()) {
23 boost::python::object main = boost::python::import(
"__main__");
24 const char* startup = getenv(
"PYTHONSTARTUP");
26 FILE *fp = fopen(startup,
"r");
27 if (fp) PyRun_SimpleFile(fp, startup);
32 PyRun_SimpleString(
"import signal\n"
33 "signal.signal(signal.SIGINT, signal.SIG_DFL)\n");
40 PyImport_AddModule(
"mpqc");
41 PyRun_SimpleString(
"import mpqc");
54 static initializer init;
57 struct tuple : boost::python::tuple {
60 : boost::python::tuple(boost::python::make_tuple(t)) {}
61 template<
typename T0,
typename T1>
63 : boost::python::tuple(boost::python::make_tuple(t0,t1)) {}
64 template<
typename T0,
typename T1,
typename T2,
typename T3>
65 tuple(T0 t0, T1 t1, T2 t2, T3 t3)
66 : boost::python::tuple(boost::python::make_tuple(t0,t1,t2,t3)) {}
73 void exec(
const std::string &cmd) {
74 std::cout << cmd << std::endl;
75 PyRun_SimpleString(cmd.c_str());
78 void exec(
const boost::python::object &cmd) {
79 exec(boost::python::extract<std::string>(cmd));
83 namespace py = boost::python;
85 PyRun_InteractiveLoop(stdin,
"<stdin>");
113 #endif // HAVE_PYTHON