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?

2
  • Print the actual Python error using PyErr_Print() to get a better idea. Most likely Namespace does not exist. Commented Oct 7, 2022 at 22:25
  • Can confirm Namespace was not existing Commented Feb 10, 2023 at 18:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.