Another C API Question
beginner
zyzhu2000 at gmail.com
Fri Jul 27 10:11:28 EDT 2007
Hi Farshid,
On Jul 26, 8:18 pm, Farshid Lashkari <n... at spam.com> wrote:
> beginner wrote:
> > I know obj is a number, but I do not know the exact type. How can I
> > convert it to double without writing a giant switch() that exhausts
> > every single type of number?
>
> Try using the PyFloat_AsDouble(...) function, it should be able to
> convert an object to a double, as long as the object implements the
> __float__ method.
This works with PyFloat only. It does not work with integers.
Thanks,
b
More information about the Python-list
mailing list