[C++-sig] python namespace

Francois Ostiguy ostiguy at fnal.gov
Wed Nov 20 22:58:37 CET 2002


Hi -

I am trying to do the following:

suppose I have two functions f1 and f2. I would like to map those
functions to two different python "module" namespaces

i.e.

outer.inner1.f1
outer.inner2.f2

So far all my attempts have failed. In particular, I tried the following
recipe, suggested by Dave in an earlier message

namespace python = boost::python;

void f1() {
  std:: cout <<"f1" << std::endl;
}

void f2() {
  std:: cout <<"f2" << std::endl;
}


BOOST_PYTHON_MODULE(outer)
{


  python::handle<> inner_module1( PyModule_New("outer.inner1"));
  python::scope inner_scope1 =  object(inner_module1);

  python::def("f1", &f1);

  python::handle<> inner_module2( PyModule_New("outer.inner2"));
  python::scope inner_scope2 =  object(inner_module2);

  python::def("f2", &f2);

 }


It fails with the following message:

namespace.cc: In function `void init_module_outer()':
namespace.cc:29: non-lvalue in unary `&'
namespace.cc:29: no match for call to `(boost::python::api::object) (
   boost::python::handle<PyObject>&)'
/usr/local/ap/include/boost/python/object_core.hpp:101: candidates are:
   boost::python::api::object
   boost::python::api::object_operators<U>::operator()() const [with U =
   boost::python::api::object]
/usr/local/ap/include/boost/python/object_call.hpp:16:
   boost::python::detail::dependent<boost::python::api::object, A0>::type
   boost::python::api::object_operators<U>::operator()(const A0&) const
[with
   A0 = boost::python::handle<PyObject>, U = boost::python::api::object]
namespace.cc:33: non-lvalue in unary `&'

Any ideas on how to achieve the desired result ?


-Francois

----------------------------------------------------------------------------
Dr. Jean-Francois OSTIGUY                              voice: (630) 840-2231
Beam Physics Dept MS220                                  FAX: (630) 840-6039
Fermi National Accelerator Laboratory                email: ostiguy at fnal.gov
Batavia IL 60510-0500                           WWW:www-ap.fnal.gov/~ostiguy






More information about the Cplusplus-sig mailing list