[C++-sig] to_python

David Abrahams david.abrahams at rcn.com
Wed Feb 27 15:35:37 CET 2002

Sorry, I'm going to have to ask you to be more specific.

----- Original Message -----
From: "Robert Andre" <randre at pppl.gov>

> I have a c++ array type called uarray which I would like to wrap
> so that the python return type might be a double or a new uarray.

The python return type of what?

> I am trying to create a helper function such as
>   PyObject* uarray_getitem(const uarray&, PyObject* p) ;
> to wrap as __getitem__.

A member of some extension class, I presume?

> But I am having trouble because I want to
> call  to_python(my_uarray)  when the return type should be a uarray
> but the compiler complains about not having a definition for the
> to_python(uarray) function:
> /usr/local/include/boost/python/detail/extension_class.hpp: In function
>    `PyObject* boost::python::to_python(const T&) [with T =
> array_boost.cc:41:   instantiated from here
> /usr/local/include/boost/python/detail/extension_class.hpp:393:
>    undeclared (first use this function)
> /usr/local/include/boost/python/detail/extension_class.hpp:393: (Each
>    undeclared identifier is reported only once for each function it
>    in.)

Have you exposed uarray to python with a class_builder<uarray>?
If so, you need to be sure the class_builder instantiation is visible
/before/ def(uarray_getitem...) is called to expose uarray_getitem to

> So, a couple of questions:
> 1) Is creating a helper function with PyObjects the right approach?

Hard to say. You haven't made clear what you're trying to accomplish.

> 2) Is there a way to declare to_python() functions for user types
> explicitly in a header outside of the BOOST_PYTHON_MODULE_INIT block?

Sure, they're just C++ functions; you can declare them in the ordinary way.


More information about the Cplusplus-sig mailing list