writing a generic method
jepler at unpythonic.net
jepler at unpythonic.net
Mon Nov 21 09:47:00 EST 2005
You could use a format like "#s#sO", and then use PyFloat_Check,
PyFloat_AsDouble, and the equivalent PyInt macros to get the "C" value out of
the Python object.
You should be able to use the converter "O&" to get what you want. The
conversion function might look like:
int double_only(PyObject *o, double *d) {
if(!PyFloat_Check(o)) return 0;
*d = PyFloat_AsDouble(o);
}
and the call would be
if(PyArg_ParseTuple(args,"s#s#O&",&cname,&lname,&cprop,&lprop,double_only,&x))
mdbgetd_(cname,cprop,&x,&z,lname,lprop);
(untested)
I believe that if you write
if(PyArg_ParseTuple(...))
else(PyArg_ParseTuple(...))
you're missing a PyErr_Clear() before the second PyArg_ParseTuple(). Returning
non-NULL when an exception has been set in C code will lead to a hard-to-trace
failure down the road.
Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051121/af99ce6c/attachment.sig>
More information about the Python-list
mailing list