Another C API Question

beginner zyzhu2000 at gmail.com
Fri Jul 27 10:10:31 EDT 2007


Hi Robert,

On Jul 26, 8:16 pm, Robert Kern <robert.k... at gmail.com> wrote:
> beginner wrote:
> > Hi,
>
> > I run into another C API question. What is the simplest way to convert
> > an PyObject into a double?
>
> > For example, I have
>
> >  PyObject *obj;
>
> > 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?
>
> Convert it to a Python float using PyNumber_Float(), then use PyFloat_AsDouble()
> to get the C double value from it.
>

Thanks a lot for your help.

Best regards,
beginner





More information about the Python-list mailing list