Re: Another C API Question

2007-07-27 Thread beginner
Hi Farshid, On Jul 26, 8:18 pm, Farshid Lashkari [EMAIL PROTECTED] 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

Re: Another C API Question

2007-07-27 Thread beginner
Hi Robert, On Jul 26, 8:16 pm, Robert Kern [EMAIL PROTECTED] 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

Re: Another C API Question

2007-07-27 Thread Farshid Lashkari
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. -- http://mail.python.org/mailman/listinfo/python-list

Re: Another C API Question

2007-07-27 Thread beginner
On Jul 27, 11:37 am, Farshid Lashkari [EMAIL PROTECTED] 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

Re: Another C API Question

2007-07-27 Thread beginner
On Jul 27, 4:50 pm, Farshid Lashkari [EMAIL PROTECTED] wrote: beginner wrote: 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. That's strange. I

Re: Another C API Question

2007-07-27 Thread beginner
On Jul 27, 4:50 pm, Farshid Lashkari [EMAIL PROTECTED] wrote: beginner wrote: 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. That's strange. I

Re: Another C API Question

2007-07-27 Thread Farshid Lashkari
beginner wrote: 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. That's strange. I just tried the following code: fprintf(stdout,True =

Re: Another C API Question

2007-07-26 Thread Farshid Lashkari
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

Re: Another C API Question

2007-07-26 Thread Robert Kern
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

Another C API Question

2007-07-26 Thread beginner
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