[C++-sig] V2: to_python/from_python questions
Pearu Peterson
pearu at cens.ioc.ee
Mon Apr 22 21:57:51 CEST 2002
Hi Dave,
On Mon, 22 Apr 2002, David Abrahams wrote:
> I think you will find your answer here. In some ways I find it to be an
> immense relief:
Yes, I can understand it.
> The upshot is that you can ignore coerce and just overload your __add__
> and __radd__ method to work with floats.
Instead of defining a punch of add methods like
const GiNaC::ex ex_add(const GiNaC::ex&,double);
const GiNaC::ex ex_add(const GiNaC::ex&,int);
const GiNaC::ex ex_add(const GiNaC::ex&,const GiNaC::ex&);
const GiNaC::ex ex_add(const GiNaC::ex&,const GiNaC::basic&);
const GiNaC::ex ex_add(const GiNaC::ex&,complex);
I am thinking of having a single one
const GiNaC::ex ex_add(const GiNaC::ex&,PyObject*);
It ignores V2 overloading stuff. Is there any downside of doing this
except having my own bugs?
And I am a bit confused about to_python and from_python that, I think,
understand from V1 perspective. Is there a simple correspondence between
these facilities in V1 and V2?
In V2 I have used, for example
boost::python::to_python_value<const GiNaC::ex&>()(e)
to construct a PyObject of e. Is this the correct way?
There is also to_python_indirect and to_python_converter. When one should
use them and how?
Also I have used
boost::python::converter::reference_from_python<const GiNaC::basic&>(obj)(obj)
to get GiNaC::basic& from PyObject obj. This looks clumsy (using two
times obj). Is there a more appropriate way for getting C++ objects for
Python objects?
I see that there are also from_python, value_from_python.
How and when they should be used?
It took some time for me to figure out how to use this
reference_from_python and I am still not sure that I am using it
correctly.
Pearu
More information about the Cplusplus-sig
mailing list