• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PySequence_Length函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PySequence_Length函数的典型用法代码示例。如果您正苦于以下问题:C++ PySequence_Length函数的具体用法?C++ PySequence_Length怎么用?C++ PySequence_Length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PySequence_Length函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: PySequence_Length

PyObject *wrap_calc_fit_R(PyObject *self,PyObject *args)
{

  PyObject *cs1, *cs2, *mass;
  if(!PyArg_ParseTuple(args,"OOO",&cs1, &cs2, &mass))
    return NULL;
  int natoms1 = PySequence_Length(cs1);
  int natoms2 = PySequence_Length(cs2);
  if( natoms1 != natoms2 ) {
    Error("Cannot fit coordinate sets with different lengths");
  }
  rvec x1[natoms1];
  rvec x2[natoms1];
  real m[natoms1];
  PyObject2rvec( cs1, x1, natoms1);
  PyObject2rvec( cs2, x2, natoms2);
  PyObject2real_array(mass, m, natoms1);
  center(x1, natoms1);
  center(x2, natoms1);
  matrix R;
  clear_mat(R);
  calc_fit_R(natoms1,m,x1,x2,R);
  PyObject *ret = matrix2PyObject(R);
  return ret;
}
开发者ID:esguerra,项目名称:pmx,代码行数:25,代码来源:wrap_Geometry.c


示例2: build_b14_from_bonds

void build_b14_from_bonds(PyObject *atomlist )
{

  int i,k, l;
  int natoms = PySequence_Length(atomlist);
  for(i=0;i<natoms;i++){
    PyObject *atom = PySequence_GetItem(atomlist, i);
    PyObject *b14 = PyObject_GetAttrString(atom,"b14");
    int atom_id = PyInt_AsLong (PyObject_GetAttrString(atom,"id") );

    PyObject *b13 = PyObject_GetAttrString(atom,"b13");
    int len_b13 = PySequence_Length(b13);
    for(k=0;k<len_b13;k++){
      PyObject *bb = PySequence_GetItem(b13, k);
      PyObject *bb_bonds = PyObject_GetAttrString(bb,"bonds");
      int len_bonds = PySequence_Length(bb_bonds);
      for(l=0;l<len_bonds;l++){
	PyObject *bond = PySequence_GetItem(bb_bonds, l);
	int atom_id2 = PyInt_AsLong (PyObject_GetAttrString(bond,"id") );
	if( atom_id < atom_id2  && ! is_bound(atom, atom_id2 -1 )) {
	  PyObject *bb14 = PyObject_GetAttrString(bond,"b14");
	  PyList_Append(b14, bond );
	  PyList_Append(bb14, atom );
	}
      }
    }
  }
}
开发者ID:esguerra,项目名称:pmx,代码行数:28,代码来源:wrap_Geometry.c


示例3: create_Group

PyObject* create_Group(PyObject* args){
  if (PySequence_Length(args) == 0){
    throw TypeError("A group must contain at least one object");
  }

  // Use either the function arguments as the sequence of objects, or
  // a single sequence-argument as the sequence. i.e. allow both
  // Group(a, b, c, d) and Group([a,b,c,d])
  PyObject* sequence = (PySequence_Length(args) == 1 &&
    PySequence_Check(PySequence_GetItem(args, 0))) ?
    PySequence_GetItem(args, 0) :
    args;

  const auto n = PySequence_Length(sequence);
  // Prevent empty seguence arguments groups, i.e. Group([])
  if (n == 0){
    throw TypeError("A group must contain at least one object.");
  }

  objects_t faintObjects;
  for (int i = 0; i != n; i++){
    PyObject* object = PySequence_GetItem(sequence, i);
    if (!PyObject_IsInstance(object, (PyObject*)&ShapeType)){
      throw TypeError("Unsupported item in list");
    }

    faintObjects.push_back(proxy_shape(object));
  }

  Object* group = create_composite_object_raw(faintObjects, Ownership::OWNER);
  return create_Shape(group);
}
开发者ID:lukas-ke,项目名称:faint-graphics-editor,代码行数:32,代码来源:py-shape.cpp


示例4: victorDist

static float
victorDist(PyObject *d1, PyObject *d2, float cost)
{
	float dist=0.0;
	float last=1.0;
	float *lasti;
	int i,j, dl1, dl2;
	dl1 =(int)PySequence_Length(d1); 
	dl2 =(int)PySequence_Length(d2); 
	if (dl1== 0) {
		return (float)dl2;
	} else if (dl2 ==0) {
		return (float)dl1;
	}
	lasti=(float *)malloc((dl2+1)*sizeof(float));
	for (i=0;i<dl2+1;i++) {
		lasti[i]=i;
	}
	for (i=1;i<dl1+1; i++) {
		if (i>1) lasti[dl2]=last;
		last=i;
		for (j=1;j<dl2+1;j++) {
			dist=min3(lasti[j]+1, last+1, lasti[j-1]+cost*abs(intat(d1, i-1) - intat(d2, j-1)));
			lasti[j-1]=last;
			last=dist;
		}
	}	
	free(lasti);
	return dist;
}
开发者ID:gic888,项目名称:gicdat,代码行数:30,代码来源:eventtrains.c


示例5: connectPool_repr

static PyObject*
connectPool_repr(PyConnectPoolObject *v)
{
    //printf("connectPool_repr\n");
    char buf[64 + NAME_MAX];
    PyOS_snprintf(buf, sizeof(buf), "connect to %s in port %d with %d busy and %d free",
                  v->db, v->port, PySequence_Length(v->cons_busy), PySequence_Length(v->cons_free));
    return PyString_FromString(buf);
}
开发者ID:yuriyao,项目名称:MYSQLPD,代码行数:9,代码来源:mysql_c.c


示例6: convert_2d_pylist

int convert_2d_pylist( PyObject *list, double ***array, int *rows, int *cols ) {
    int i, j;
    PyObject *item;
    PyObject *num;
    // Is the object a list?
    if (!PyList_Check(list))
        return -1;
    *rows = PySequence_Length(list);
    
    // Does the list contain elements?
    if (*rows < 0) {
        return -1;
    }

    item = PySequence_GetItem(list,0);
    if(!PySequence_Check(item)) {
        return -1;
    }
    *cols = PySequence_Length(item);
    if(*cols < 0) {
        return -1;
    }
    Py_DECREF(item);

    *array = (double **)malloc(*rows * sizeof(double*) );
    for( i = 0; i < *rows; i++ ) {
        (*array)[i] = (double*)malloc(*cols*sizeof(double));
    }
        
    
    for( i = 0; i < *rows; i++ ) {
        item = PySequence_GetItem(list,i);
        if(!PySequence_Check(item)) {
            return -1;
        }
        if( PySequence_Length(item) != *cols) {
            return -1;
        }
        for( j = 0; j < *cols; j++ ) {
            num = PySequence_GetItem( item, j );
            if (PyInt_Check(num)) {
                (*array)[i][j] = (double)PyInt_AsLong( num );
            }
            else if (PyLong_Check(num)) {
                (*array)[i][j] = PyLong_AsDouble( num );
            }
            else if (PyFloat_Check(num)) {
                (*array)[i][j] = PyFloat_AsDouble( num );
            }
            else {
                return -1;
            }
        }
        Py_DECREF(item);        
    }
    return 0;
}
开发者ID:josephcourtney,项目名称:compass,代码行数:57,代码来源:util.c


示例7: mqttv3_subscribeMany

static PyObject* mqttv3_subscribeMany(PyObject* self, PyObject *args)
{
	MQTTClient c;
	PyObject* topicList;
	PyObject* qosList;

	int count;
	char** topics;
	int* qoss;

	int i, rc = 0;

	if (!PyArg_ParseTuple(args, "kOO", &c, &topicList, &qosList))
		return NULL;

	if (!PySequence_Check(topicList) || !PySequence_Check(qosList))
	{
		PyErr_SetString(PyExc_TypeError,
				"3rd and 4th parameters must be sequences");
		return NULL;
	}

	if ((count = PySequence_Length(topicList)) != PySequence_Length(qosList))
	{
		PyErr_SetString(PyExc_TypeError,
				"3rd and 4th parameters must be sequences of the same length");
		return NULL;
	}

	topics = malloc(count * sizeof(char*));
	for (i = 0; i < count; ++i)
		topics[i] = PyString_AsString(PySequence_GetItem(topicList, i));

	qoss = malloc(count * sizeof(int));
	for (i = 0; i < count; ++i)
		qoss[i] = (int) PyInt_AsLong(PySequence_GetItem(qosList, i));

	Py_BEGIN_ALLOW_THREADS rc = MQTTClient_subscribeMany(c, count, topics,
			qoss);
	Py_END_ALLOW_THREADS

	for (i = 0; i < count; ++i)
		PySequence_SetItem(qosList, i, PyInt_FromLong((long) qoss[i]));

	free(topics);
	free(qoss);

	if (rc == MQTTCLIENT_SUCCESS)
		return Py_BuildValue("iO", rc, qosList);
	else
		return Py_BuildValue("i", rc);
}
开发者ID:CJxD,项目名称:paho.mqtt.c,代码行数:52,代码来源:mqttclient_module.c


示例8: Polygon_Raise

static PyObject *Polygon_addContour(Polygon *self, PyObject *args) {
#ifdef WITH_NUMERIC
    PyObject *a=NULL;
    gpc_vertex_list *vl;
    int hole = 0;
    if (! PyArg_ParseTuple(args, "O|i", &a, &hole))
        return Polygon_Raise(ERR_ARG);
    if ((a = PyArray_ContiguousFromObject(a, PyArray_DOUBLE, 2, 2)) == NULL)
        return Polygon_Raise(ERR_ARG);
    if (((PyArrayObject *)a)->nd != 2)            return Polygon_Raise(ERR_ARG);
    if (((PyArrayObject *)a)->dimensions[1] != 2) return Polygon_Raise(ERR_ARG);
    vl = PyMem_New(gpc_vertex_list, 1);
    vl->num_vertices = ((PyArrayObject *)a)->dimensions[0];
    vl->vertex = PyMem_New(gpc_vertex, vl->num_vertices);
    memcpy((vl->vertex), (((PyArrayObject *)a)->data), 2*vl->num_vertices*sizeof(double));
    Py_DECREF(a);
#else
    PyObject *list=NULL, *flist, *point=NULL, *X, *Y;
    gpc_vertex_list *vl;
    gpc_vertex *v;
    int i, imax, hole = 0;
    if (! PyArg_ParseTuple(args, "O|i", &list, &hole))
        return Polygon_Raise(ERR_ARG);
    if (! PySequence_Check(list))
        return Polygon_Raise(ERR_ARG);
    flist = PySequence_Fast(list, "this is not a sequence");
    if ((! flist) || ((imax = PySequence_Length(flist)) <= 2))
        return Polygon_Raise(ERR_INV);
    vl = PyMem_New(gpc_vertex_list, 1);
    vl->num_vertices = imax;
    vl->vertex = v = PyMem_New(gpc_vertex, imax);
    for (i=0; i<imax; i++) {
        point = PySequence_Fast(PySequence_Fast_GET_ITEM(flist, i), "this is not a point");
        if ((!point) || (PySequence_Length(point) != 2))
            return Polygon_Raise(ERR_INV);
        v->x = PyFloat_AsDouble(X = PyNumber_Float(PySequence_Fast_GET_ITEM(point, 0)));
        v->y = PyFloat_AsDouble(Y = PyNumber_Float(PySequence_Fast_GET_ITEM(point, 1)));
        v++;
        Py_DECREF(X);
        Py_DECREF(Y);
        Py_DECREF(point);
    }
    Py_DECREF(flist);
#endif /* WITH_NUMERIC */
    gpc_add_contour(self->p, vl, hole);
    self->bbValid = 0;
    PyMem_Free(vl->vertex);
    PyMem_Free(vl);
    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:anujonthemove,项目名称:supreme,代码行数:51,代码来源:cPolygon.c


示例9: Config_init

int
Config_init(Config *self, PyObject *args, PyObject *kwds)
{
    char *path;
    int err;

    if (kwds) {
        PyErr_SetString(PyExc_TypeError,
                        "Repository takes no keyword arguments");
        return -1;
    }

    if (PySequence_Length(args) > 0) {
        if (!PyArg_ParseTuple(args, "s", &path)) {
            return -1;
        }

        err = git_config_open_ondisk(&self->config, path);

    } else {
        err = git_config_new(&self->config);
    }

    if (err < 0) {
        if (err == GIT_ENOTFOUND) {
            Error_set_exc(PyExc_IOError);
        } else {
            Error_set(err);
        }

        return -1;
    }

    return 0;
}
开发者ID:cboos,项目名称:pygit2,代码行数:35,代码来源:config.c


示例10: Connect

static bool Connect(PyObject* pConnectString, HDBC hdbc, bool fAnsi, long timeout,
                    Object& encoding)
{
    // This should have been checked by the global connect function.
    I(PyString_Check(pConnectString) || PyUnicode_Check(pConnectString));

    const int cchMax = 600;

    if (PySequence_Length(pConnectString) >= cchMax)
    {
        PyErr_SetString(PyExc_TypeError, "connection string too long");
        return false;
    }

    // The driver manager determines if the app is a Unicode app based on whether we call SQLDriverConnectA or
    // SQLDriverConnectW.  Some drivers, notably Microsoft Access/Jet, change their behavior based on this, so we try
    // the Unicode version first.  (The Access driver only supports Unicode text, but SQLDescribeCol returns SQL_CHAR
    // instead of SQL_WCHAR if we connect with the ANSI version.  Obviously this causes lots of errors since we believe
    // what it tells us (SQL_CHAR).)

    // Python supports only UCS-2 and UCS-4, so we shouldn't need to worry about receiving surrogate pairs.  However,
    // Windows does use UCS-16, so it is possible something would be misinterpreted as one.  We may need to examine
    // this more.

    SQLRETURN ret;

    if (timeout > 0)
    {
        Py_BEGIN_ALLOW_THREADS
        ret = SQLSetConnectAttr(hdbc, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER)(uintptr_t)timeout, SQL_IS_UINTEGER);
        Py_END_ALLOW_THREADS
        if (!SQL_SUCCEEDED(ret))
            RaiseErrorFromHandle("SQLSetConnectAttr(SQL_ATTR_LOGIN_TIMEOUT)", hdbc, SQL_NULL_HANDLE);
    }
开发者ID:expobrain,项目名称:pyodbc,代码行数:34,代码来源:connection.cpp


示例11: read_det_list

static Detection_t * read_det_list(PyObject * det_list_obj, int * out_num_det)
/* Read a Python list of Detection tuples and return a C
 * list of Detection_t objects that has to be freed with free_det_list */
{
  int num_det = (int) PySequence_Length(det_list_obj);
  
  Detection_t * det_list = (Detection_t *)malloc(num_det * sizeof(Detection_t));

  int detidx;
  
  for (detidx = 0; detidx < num_det; detidx ++)
  {
    /* new reference */
    PyObject * det_obj = PySequence_GetItem(det_list_obj, (Py_ssize_t) detidx);

    PyArg_ParseTuple(det_obj, "idddd", &det_list[detidx].staidx,
                     &det_list[detidx].time, &det_list[detidx].azimuth,
                     &det_list[detidx].slowness, &det_list[detidx].amp);


#ifdef VERYVERBOSE
    printf("staidx %d time %lf azimuth %lf slowness %lf amp %lf\n", 
           det_list[detidx].staidx,
           det_list[detidx].time, det_list[detidx].azimuth, 
           det_list[detidx].slowness, det_list[detidx].amp);
#endif

    Py_DECREF(det_obj);
  }

  *out_num_det = num_det;
  return det_list;
}
开发者ID:calonlay-hj,项目名称:ppaml-cp4,代码行数:33,代码来源:csolve.c


示例12: PyMAPIObject_AsSPropValueArray

// @object PySPropValueArray|A sequence of <o PySPropValue>, as passed to many MAPI functions.
BOOL PyMAPIObject_AsSPropValueArray(PyObject *obs, SPropValue **ppv, ULONG *pcValues)
{
    int seqLen = PySequence_Length(obs);
    SPropValue *pPV;
    HRESULT hr;
    if (S_OK != (hr=MAPIAllocateBuffer(sizeof(SPropValue) * seqLen, (void **)&pPV))) {
        OleSetOleError(hr);
        return FALSE;
    }
    for (ULONG i=0; i<(ULONG)seqLen; i++) {
        PyObject *myob = PySequence_GetItem(obs, i);
        if (myob==NULL)	{
            MAPIFreeBuffer(pPV);
            return FALSE;
        }
        BOOL rc = PyMAPIObject_AsSPropValue(myob, pPV+i, pPV);
        Py_DECREF(myob);
        if (!rc) {
            MAPIFreeBuffer(pPV);
            return FALSE;
        }
    }
    *pcValues = seqLen;
    *ppv = pPV;
    return TRUE;
}
开发者ID:mcg1969,项目名称:pywin32,代码行数:27,代码来源:mapiutil.cpp


示例13: Affine_itransform

static PyObject *
Affine_itransform(polypaths_planar_overrideAffineObject *self, PyObject *seq)
{
    Py_ssize_t i;
    Py_ssize_t len;
    PyObject *point;
    polypaths_planar_overrideSeq2Object *varray;
    double x, y, a, b, c, d, e, f;

    a = self->a;
    b = self->b;
    c = self->c;
    d = self->d;
    e = self->e;
    f = self->f;
    assert(polypaths_planar_overrideAffine_Check(self));
    if (polypaths_planar_overrideSeq2_Check(seq)) {
	/* Optimized code path for Seq2s */
	varray = (polypaths_planar_overrideSeq2Object *)seq;
	for (i = 0; i < Py_SIZE(seq); i++) {
	    x = varray->vec[i].x;
	    y = varray->vec[i].y;
	    varray->vec[i].x = x*a + y*d + c;
	    varray->vec[i].y = x*b + y*e + f;
	}
    } else {
		/* General vector sequence */
		len = PySequence_Length(seq);
		if (len == -1) {
			PyErr_SetString(PyExc_TypeError, 
			"Affine.itransform(): Cannot transform non-sequence");
			return NULL;
		}
		for (i = 0; i < len; i++) {
			point = PySequence_GetItem(seq, i);
			if (point == NULL) {
				return NULL;
			}
			if (!polypaths_planar_overrideVec2_Parse(point, &x, &y)) {
				Py_DECREF(point);
				PyErr_Format(PyExc_TypeError, 
					"Affine.itransform(): "
					"Element at position %lu is not a valid vector", i);
				return NULL;
			}
			Py_DECREF(point);
			point = (PyObject *)polypaths_planar_overrideVec2_FromDoubles(x*a + y*d + c, x*b + y*e + f);
			if (point == NULL) {
				return NULL;
			}
			if (PySequence_SetItem(seq, i, point) < 0) {
			Py_DECREF(point);
				return NULL;
			}
			Py_DECREF(point);
		}
    }
    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:apolcyn,项目名称:polypaths_planar_override,代码行数:60,代码来源:ctransform.c


示例14: set_installonly

static int
set_installonly(_SackObject *self, PyObject *obj, void *unused)
{
    if (!PySequence_Check(obj)) {
        PyErr_SetString(PyExc_AttributeError, "Expected a sequence.");
        return -1;
    }

    const int len = PySequence_Length(obj);
    PycompString pStrings[len];
    const char *strings[len + 1];

    for (int i = 0; i < len; ++i) {
        UniquePtrPyObject item(PySequence_GetItem(obj, i));
        if (PyUnicode_Check(item.get()) || PyString_Check(item.get())) {
            pStrings[i] = PycompString(item.get());
            strings[i] = pStrings[i].getCString();
        } else
            strings[i] = NULL;
        if (strings[i] == NULL)
            return -1;
    }
    strings[len] = NULL;

    DnfSack *sack = self->sack;
    dnf_sack_set_installonly(sack, strings);

    return 0;
}
开发者ID:rpm-software-management,项目名称:libhif,代码行数:29,代码来源:sack-py.cpp


示例15: printf

unsigned char *convert_uchar_array(unsigned char *result,PyObject *input, int size) {
  int i;
  if (!PySequence_Check(input)) {
    printf("Expected a sequence\n");
    exit(EXIT_FAILURE);
  }
  int length=PySequence_Length(input);
  if (length > size) {
    printf("Size mismatch.\n");
    exit(EXIT_FAILURE);
  }
//  result = (unsigned char *) malloc(size*sizeof(unsigned char));
  if(result==NULL)
  {
    fprintf(stderr,"Unable to allocate %d bytes.\n",(size*sizeof(unsigned char)));
    return result;
  }
  for (i = 0; i < length; i++) {
    PyObject *o = PySequence_GetItem(input,i);
    if (PyNumber_Check(o)) {
      if(PyFloat_AsDouble(o)>255)
        result[i] = (unsigned char) 255;
      else
        result[i] = (unsigned char) PyFloat_AsDouble(o);
    } else {
      PyErr_SetString(PyExc_ValueError,"uchar: Sequence elements must be numbers");
      free(result);       
      return NULL;
    }
    free(o);
  }
  return result;
}
开发者ID:kstovall,项目名称:psrfits_utils,代码行数:33,代码来源:swig_addedfunc.c


示例16: SKAux_IdIndex

PyObject *
SKAux_IdIndex(PyObject * self, PyObject * args)
{
    PyObject * list, *obj, *item;
    int length, i, equal;

    if (!PyArg_ParseTuple(args, "OO", &list, &obj))
	return NULL;

    if (!PySequence_Check(list))
    {
	PyErr_SetString(PyExc_TypeError, "argument must be a sequence");
	return NULL;
    }

    length = PySequence_Length(list);

    for (i = 0; i < length; i++)
    {
	item = PySequence_GetItem(list, i);
	equal = (item == obj);
	Py_DECREF(item);
	if (equal)
	    break;
    }

    if (i < length)
	return PyInt_FromLong(i);

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:dlajarretie,项目名称:uniconvertor,代码行数:32,代码来源:skaux.c


示例17: pixmap_CreateGC

static PyObject *
pixmap_CreateGC(PaxPixmapObject *self, PyObject *args, PyObject * kwargs)
{
    Display *display;
    Drawable d;
    unsigned long mask = 0;
    XGCValues values;
    GC gc;
    PyObject * dict;

    if (PySequence_Length(args) > 0)
    {
	if (!PyArg_ParseTuple(args, "O", &dict))
	    return NULL;
    }
    else
	dict = kwargs;

    display = self->display;
    d = self->pixmap;

    if (dict)
    {
	if (!PaxGC_MakeValues(dict, &mask, &values))
	    return NULL;
    }

    gc = XCreateGC(display, d, mask, &values);
    return PaxGC_FromGC(display, d, gc, PAXGC_OWNED, (PyObject*)self);
}
开发者ID:kindlychung,项目名称:sk1,代码行数:30,代码来源:pixmapobject.c


示例18: parse_filter_chain_spec

static int
parse_filter_chain_spec(lzma_filter filters[], PyObject *filterspecs)
{
    Py_ssize_t i, num_filters;

    num_filters = PySequence_Length(filterspecs);
    if (num_filters == -1)
        return -1;
    if (num_filters > LZMA_FILTERS_MAX) {
        PyErr_Format(PyExc_ValueError,
                     "Too many filters - liblzma supports a maximum of %d",
                     LZMA_FILTERS_MAX);
        return -1;
    }

    for (i = 0; i < num_filters; i++) {
        int ok = 1;
        PyObject *spec = PySequence_GetItem(filterspecs, i);
        if (spec == NULL || !lzma_filter_converter(spec, &filters[i]))
            ok = 0;
        Py_XDECREF(spec);
        if (!ok) {
            filters[i].id = LZMA_VLI_UNKNOWN;
            free_filter_chain(filters);
            return -1;
        }
    }
    filters[num_filters].id = LZMA_VLI_UNKNOWN;
    return 0;
}
开发者ID:Alex9029,项目名称:cpython,代码行数:30,代码来源:_lzmamodule.c


示例19: SPOLStatement

static PyObject *PSetIDR(PyObject *self, PyObject *args) {
  int idr, ndr, i;
  double *pdr;
  PyObject *p, *q;

  if (spol_file) {
    SPOLStatement("SetIDR", args, NULL);
    Py_INCREF(Py_None);
    return Py_None;
  }
  
  p = NULL;
  if (!PyArg_ParseTuple(args, "i|O", &idr, &p)) return NULL;

  ndr = 0;
  pdr = NULL;
  if (p) {
    if (!PyList_Check(p) && !PyTuple_Check(p)) return NULL;
    ndr = PySequence_Length(p);
    pdr = (double *) malloc(sizeof(double)*ndr);
    for (i = 0; i < ndr; i++) {
      q = PySequence_GetItem(p, i);
      pdr[i] = PyFloat_AsDouble(q);
      Py_DECREF(q);
    }
  }
  
  if (SetIDR(idr, ndr, pdr) < 0) return NULL;

  Py_INCREF(Py_None);
  return Py_None;
} 
开发者ID:fnevgeny,项目名称:fac,代码行数:32,代码来源:ppol.c


示例20: mqttv3_unsubscribeMany

static PyObject* mqttv3_unsubscribeMany(PyObject* self, PyObject *args)
{
	MQTTClient c;
	PyObject* topicList;

	int count;
	char** topics;

	int i, rc = 0;

	if (!PyArg_ParseTuple(args, "kOO", &c, &topicList))
		return NULL;

	if (!PySequence_Check(topicList))
	{
		PyErr_SetString(PyExc_TypeError, "3rd parameter must be sequences");
		return NULL;
	}

	count = PySequence_Length(topicList);
	topics = malloc(count * sizeof(char*));
	for (i = 0; i < count; ++i)
		topics[i] = PyString_AsString(PySequence_GetItem(topicList, i));

	Py_BEGIN_ALLOW_THREADS rc = MQTTClient_unsubscribeMany(c, count, topics);
	Py_END_ALLOW_THREADS

	free( topics);

	return Py_BuildValue("i", rc);
}
开发者ID:CJxD,项目名称:paho.mqtt.c,代码行数:31,代码来源:mqttclient_module.c



注:本文中的PySequence_Length函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PySequence_Size函数代码示例发布时间:2022-05-30
下一篇:
C++ PySequence_ITEM函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap