Another C API Question
beginner
zyzhu2000 at gmail.com
Fri Jul 27 17:18:56 EDT 2007
On Jul 27, 11:37 am, Farshid Lashkari <n... at spam.com> wrote:
> beginner wrote:
> > This works with PyFloat only. It does not work with integers.
>
> Did you try it out? I have used it on ints, bools, and objects that
> implement the __float__ method. It does not work on strings though.
I did and it did not seem to work. I ended up doing the following.
Verbose, isn't it?
If I do d=PyFloat_AsDouble(oDiscount); in the third "if", I get an
error. Maybe I missed something obvious.
if(oDiscount==Py_None)
{
}
else if(PyFloat_Check(oDiscount))
{
d=PyFloat_AsDouble(oDiscount);
}
else if(PyNumber_Check(oDiscount))
{
PyObject *pf=PyNumber_Float(oDiscount);
if(pfDiscount)
{
d=PyFloat_AsDouble(pfDiscount);
Py_DECREF(pfDiscount);
}
}
else ...
More information about the Python-list
mailing list