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.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to