
Untitled
By: a guest on
Aug 5th, 2012 | syntax:
None | size: 1.10 KB | hits: 8 | expires: Never
Python C interface PyArg_ParseTuple failing
def SetPowerSupply(voltage, current, supply):
float voltage, current;
int supply;
if (!PyArg_ParseTuple(args, "ffi", &voltage, ¤t, &supply))
{
// Failed to parse
// ...
}
PyObject *num = PyNumber_Float(PyTuple_GetItem(args, 0));
voltage = PyFloat_AsDouble(num);
Py_XDECREF(num);
num = PyNumber_Float(PyTuple_GetItem(args, 1));
current = PyFloat_AsDouble(num);
Py_XDECREF(num);
num = PyNumber_Int(PyTuple_GetItem(args, 2));
supply = PyLong_AsLong(num);
Py_XDECREF(num);
SetPowerSupply(37.5, 0.5, 1)
SetPowerSupply(0, 0, 1)
if(!PyArg_ParseTuple(args, "s|siss", &board, &component, &pin, &colorStr, &msg))
{
// Parsing the pin as an int failed, try as a string
if(!PyArg_ParseTuple(args, "s|ssss", &board, &component, &sPin, &colorStr, &msg))
{
// ...
if(!PyArg_ParseTuple(args, "s|siss", &board, &component, &pin, &colorStr, &msg))
{
PyErr_Clear();
// Parsing the pin as an int failed, try as a string
if(!PyArg_ParseTuple(args, "s|ssss", &board, &component, &sPin, &colorStr, &msg))
{
// ...