[C++-sig] Conversion from Python to C++

Stefan Seefeld seefeld at sympatico.ca
Fri Oct 2 16:22:36 CEST 2009


On 10/02/2009 10:06 AM, Michele De Stefano wrote:
> For example, assume we have two C++ classes, A and B. A is exported to
> Python with class_<>, while B is not exported to Python.
> Assume also that, in C++, A is convertible to B (i.e. I can construct
> a B object from an existing A object).
>
> Assume I have a C++ function (f) which takes a B object as input and I
> want to expose this function, but I don't want to expose the B class.
>
> Is there a general way to create a converter from A to B in order to
> be able to call f(A) from Python ?
>    

Depending on how many such functions you have, you may either simply 
write a wrapper function with the right signature (i.e. accepting an 'A' 
and (implicitly) converting that to a 'B' when calling the actual 
function), or you may write a custom from_python converter.

Regards,
         Stefan

-- 

       ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list