0

We are trying to set the namespace of a boost::python::object, with the following code

In PyROOTGlobals.h we declare:

#ifndef PyROOTGlobals_h
#define PyROOTGlobals_h

#include <boost/python.hpp>

namespace Kolophon{

 class PyROOTGlobals {

  public:

  ~PyROOTGlobals();
  const boost::python::object &wuto() const { return WutoAtlas; }

  private:
  PyROOTGlobals();

  boost::python::object WutoAtlas;
 };
}
#endif

And in PyROOTGlobals.cc we declare:

PyROOTGlobals::PyROOTGlobals()
{
  Py_Initialize();
  pyCintex = boost::python::import("cppyy");
  pyROOT = boost::python::import("ROOT");

  WutoAtlas = pyCintex.attr("Namespace")("WutoAtlas");

  mainDict = boost::python::import("__main__").attr("__dict__");

  boost::python::object builtins =
  mainDict["__builtins__"].attr("__dict__");

  compileFn = builtins["compile"];
  evalFn = builtins["eval"];

  //errorhandling
  StringIO = boost::python::import("io");
  sysModule = boost::python::import("sys");
  commonModule = boost::python::import("common");
}

But when using WutoAtlas = pyCintex.attr("Namespace")("WutoAtlas") we get a boost::python::error_already_set error. We also tried setattr(WutoAtlas,"Namespace","WutoAtlas") but same result.

Does anybody know how to set the namespace attribute with cppyy?

0 Answers0