当前位置: 首页>>代码示例>>C++>>正文


C++ PySequence_GetItem函数代码示例

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


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

示例1: PyErr_Format

//-------------------------------------------------------------------------------------
PyObject* Entity::pyTeleport(PyObject* nearbyMBRef, PyObject* pyposition, PyObject* pydirection)
{
	if(!PySequence_Check(pyposition) || PySequence_Size(pyposition) != 3)
	{
		PyErr_Format(PyExc_Exception, "%s::teleport: %d position not is Sequence!\n", getScriptName(), getID());
		PyErr_PrintEx(0);
		S_Return;
	}

	if(!PySequence_Check(pydirection) || PySequence_Size(pydirection) != 3)
	{
		PyErr_Format(PyExc_Exception, "%s::teleport: %d direction not is Sequence!\n", getScriptName(), getID());
		PyErr_PrintEx(0);
		S_Return;
	}

	Position3D pos;
	Direction3D dir;

	PyObject* pyitem = PySequence_GetItem(pyposition, 0);
	pos.x = (float)PyFloat_AsDouble(pyitem);
	Py_DECREF(pyitem);

	pyitem = PySequence_GetItem(pyposition, 1);
	pos.y = (float)PyFloat_AsDouble(pyitem);
	Py_DECREF(pyitem);

	pyitem = PySequence_GetItem(pyposition, 2);
	pos.z = (float)PyFloat_AsDouble(pyitem);
	Py_DECREF(pyitem);

	pyitem = PySequence_GetItem(pydirection, 0);
	dir.roll = (float)PyFloat_AsDouble(pyitem);
	Py_DECREF(pyitem);

	pyitem = PySequence_GetItem(pydirection, 1);
	dir.pitch = (float)PyFloat_AsDouble(pyitem);
	Py_DECREF(pyitem);

	pyitem = PySequence_GetItem(pydirection, 2);
	dir.yaw = (float)PyFloat_AsDouble(pyitem);
	Py_DECREF(pyitem);
	
	teleport(nearbyMBRef, pos, dir);
	S_Return;
}
开发者ID:fengqk,项目名称:kbengine,代码行数:47,代码来源:entity.cpp

示例2: double_from_pyobj

static int double_from_pyobj(double* v,PyObject *obj,const char *errmess) {
  PyObject* tmp = NULL;
  if (PyFloat_Check(obj)) {
#ifdef __sgi
    *v = PyFloat_AsDouble(obj);
#else
    *v = PyFloat_AS_DOUBLE(obj);
#endif
    return 1;
  }
  tmp = PyNumber_Float(obj);
  if (tmp) {
#ifdef __sgi
    *v = PyFloat_AsDouble(tmp);
#else
    *v = PyFloat_AS_DOUBLE(tmp);
#endif
    Py_DECREF(tmp);
    return 1;
  }
  if (PyComplex_Check(obj))
    tmp = PyObject_GetAttrString(obj,"real");
  else if (PyString_Check(obj) || PyUnicode_Check(obj))
    /*pass*/;
  else if (PySequence_Check(obj))
    tmp = PySequence_GetItem(obj,0);
  if (tmp) {
    PyErr_Clear();
    if (double_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}
    Py_DECREF(tmp);
  }
  {
    PyObject* err = PyErr_Occurred();
    if (err==NULL) err = uts_scsmfo_error;
    PyErr_SetString(err,errmess);
  }
  return 0;
}
开发者ID:RebeccaWPerry,项目名称:holography-gpu,代码行数:38,代码来源:uts_scsmfomodule.c

示例3: sequence_to_arrays

/*
 * Converts a Python sequence into 'count' PyArrayObjects
 *
 * seq       - Input Python object, usually a tuple but any sequence works.
 * op        - Where the arrays are placed.
 * count     - How many arrays there should be (errors if it doesn't match).
 * paramname - The name of the parameter that produced 'seq'.
 */
static int sequence_to_arrays(PyObject *seq,
                                PyArrayObject **op, int count,
                                char *paramname)
{
    int i;

    if (!PySequence_Check(seq) || PySequence_Size(seq) != count) {
        PyErr_Format(PyExc_ValueError,
                "parameter %s must be a sequence of length %d",
                paramname, count);
        return -1;
    }

    for (i = 0; i < count; ++i) {
        PyObject *item = PySequence_GetItem(seq, i);
        if (item == NULL) {
            while (--i >= 0) {
                Py_DECREF(op[i]);
                op[i] = NULL;
            }
            return -1;
        }

        op[i] = (PyArrayObject *)PyArray_FromAny(item, NULL, 0, 0, 0, NULL);
        if (op[i] == NULL) {
            while (--i >= 0) {
                Py_DECREF(op[i]);
                op[i] = NULL;
            }
            Py_DECREF(item);
            return -1;
        }

        Py_DECREF(item);
    }

    return 0;
}
开发者ID:Ethan-Yan,项目名称:numpy,代码行数:46,代码来源:compiled_base.c

示例4: PyADSIObject_AsADS_SEARCHPREF_INFOs

BOOL PyADSIObject_AsADS_SEARCHPREF_INFOs(PyObject *ob, ADS_SEARCHPREF_INFO **ppret, DWORD *pcinfos)
{
	BOOL ret = FALSE;
	if (!PySequence_Check(ob)) {
		PyErr_SetString(PyExc_TypeError, "ADS_SEARCHPREF_INFOs must be a sequence");
		return FALSE;
	}
	// Use C++ reference to make working with ppret more convenient.
	ADS_SEARCHPREF_INFO *&pret = *ppret;
	DWORD &nitems = *pcinfos;
	nitems = PySequence_Length(ob);

	pret = (ADS_SEARCHPREF_INFO *)malloc(sizeof(ADS_SEARCHPREF_INFO) * nitems);
	if (!pret) {
		PyErr_NoMemory();
		return NULL;
	}
	memset(pret, 0, sizeof(ADS_SEARCHPREF_INFO) * nitems);
	PyObject *sub = NULL;
	PyObject *obValue; // no reference
	DWORD i;
	for (i=0;i<nitems;i++) {
		PyObject *sub = PySequence_GetItem(ob, i);
		if (!sub) goto done;
		if (!PyArg_ParseTuple(sub, "iO:ADS_SEARCHPREF_INFO tuple", &pret[i].dwSearchPref, &obValue))
			goto done;
		if (!PyADSIObject_AsADSVALUE(obValue, pret[i].vValue))
			goto done;
		Py_DECREF(sub);
		sub = NULL;
	}
	ret = TRUE;
done:
	Py_XDECREF(sub);
	if (!ret && pret)
		PyADSIObject_FreeADS_SEARCHPREF_INFOs(pret, nitems);
	return ret;
}
开发者ID:malrsrch,项目名称:pywin32,代码行数:38,代码来源:PyADSIUtil.cpp

示例5: assert

static GPtrArray *create_row(PyObject *item){
	assert(item);
	GPtrArray *row = g_ptr_array_new();
	if(!row)
		return NULL;
	int i;
	for(i = 0; i < PySequence_Size(item); i++){
		PyObject *elem = PySequence_GetItem(item, i);
		if(!elem)
			goto failed;
		PyObject *elem_str = PyObject_Str(elem);
		Py_DECREF(elem);
		if(!elem_str)
			goto failed;
		g_ptr_array_add(row, g_strdup(PyString_AsString(elem_str)));
		Py_DECREF(elem_str);
	}
	return row;

failed:
	g_ptr_array_clear(row);
	return NULL;
}
开发者ID:akamajoris,项目名称:mysql-proxy-python,代码行数:23,代码来源:network-mysqld-python.c

示例6: listtoarray

double* listtoarray(PyObject* o,int *size)
{
    int length;
    double* result;
    double tempval;
    PyObject* tempObject;
    int i;
    //printf("Started List to Array\n");
    length = PySequence_Size(o);
    //printf("%d\n",length);
    result=malloc(length*sizeof(double));
    for(i=0;i<length;i++)
    {
      //printf("%d\n",i);
	tempObject=PySequence_GetItem(o,i);
	tempval=PyFloat_AsDouble(tempObject);
	//printf("%g\n",tempval);
	result[i]=tempval;
    }
    //printf("The length is: %d\n",length);
    *size=length;
    return result;
}
开发者ID:cjwiggins,项目名称:MagnetoShim,代码行数:23,代码来源:BiotSavart_LineSeg.c

示例7: save_mask

static PyObject*
save_mask(PyObject *self, PyObject *arg)
{
    int idx, size;
    PyObject *list, *item;

    if (!PyArg_ParseTuple(arg, "O", &list)) {
        return NULL;
    }

    sigemptyset(&newmask);
    size = PySequence_Length(list);
    for (idx = 0; idx < size; ++idx) {
        item = PySequence_GetItem(list, idx);
        sigaddset(&newmask, PyInt_AsLong(item));
    }

    if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) != 0) {
        Py_Exit(1);
    }

    Py_RETURN_NONE;
}
开发者ID:SoQoo,项目名称:dping,代码行数:23,代码来源:_sigpending.c

示例8: convert2_float_array

void convert2_float_array(float *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);
  }
  for (i = 0; i < length; i++) {
    PyObject *o = PySequence_GetItem(input,i);
    if (PyNumber_Check(o)) {
      result[i] = (float) PyFloat_AsDouble(o);
    } else {
      printf("Sequence elements must be numbers\n");
      free(result);       
      exit(EXIT_FAILURE);
    }
    free(o);
  }
}
开发者ID:kstovall,项目名称:psrfits_utils,代码行数:23,代码来源:swig_addedfunc.c

示例9: seqiterHasnext_capi

static Box* seqiterHasnext_capi(Box* s) noexcept {
    RELEASE_ASSERT(s->cls == seqiter_cls || s->cls == seqreviter_cls, "");
    BoxedSeqIter* self = static_cast<BoxedSeqIter*>(s);

    if (!self->b) {
        Py_RETURN_FALSE;
    }

    Box* next = PySequence_GetItem(self->b, self->idx);
    if (!next) {
        if (PyErr_ExceptionMatches(IndexError) || PyErr_ExceptionMatches(StopIteration)) {
            PyErr_Clear();
            Py_CLEAR(self->b);
            Py_RETURN_FALSE;
        }
        return NULL;
    }

    self->idx++;
    RELEASE_ASSERT(!self->next, "");
    self->next = next;
    Py_RETURN_TRUE;
}
开发者ID:ChinaQuants,项目名称:pyston,代码行数:23,代码来源:iterobject.cpp

示例10: PyErr_SetString

static PyObject *Playlist_remove_tracks(Playlist *self, PyObject *args) {
    PyObject *py_tracks;
    PyObject *item;
    sp_error err;
    int *tracks;
    int num_tracks;
    int playlist_length;
    int i;

    if(!PyArg_ParseTuple(args, "O", &py_tracks))
        return NULL;
    if (!PySequence_Check(py_tracks)) {
        PyErr_SetString(PyExc_TypeError, "expected sequence");
        return NULL;
    }
    num_tracks = PySequence_Size(py_tracks);
    tracks = (int *) malloc(sizeof(tracks)*num_tracks);
    playlist_length = sp_playlist_num_tracks(self->_playlist);
    for (i = 0; i < num_tracks; i++) {
        item = PySequence_GetItem(py_tracks, i);
        if (!PyInt_Check(item)) {
            free(tracks);
            PyErr_SetString(PyExc_TypeError, "expected sequence of integers");
            return NULL;
        }
        tracks[i] = (int)PyInt_AsLong(item);
        if (tracks[i] > playlist_length) {
            PyErr_SetString(PyExc_IndexError, "specified track does not exist");
            return NULL;
        }
        Py_DECREF(item);
    }
    Py_BEGIN_ALLOW_THREADS
    err = sp_playlist_remove_tracks(self->_playlist, tracks, num_tracks);
    Py_END_ALLOW_THREADS
    return handle_error(err);
}
开发者ID:aabilio,项目名称:pyspotify,代码行数:37,代码来源:playlist.c

示例11: PyErr_Clear

// ---------------------------------------------------
//
// Gateway Implementation
STDMETHODIMP PyGSpecifyPropertyPages::GetPages(
		/* [out] */ CAUUID __RPC_FAR * pPages)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetPages", &result);
	if (FAILED(hr)) return hr;

    int length=PyObject_Length(result);

    if(length<1 || !PySequence_Check(result) )
    {
        // Python implementation did not return a sequence
        PyErr_Clear();
        return E_NOTIMPL;
    }

    pPages->cElems=0;
    pPages->pElems=(GUID *)CoTaskMemAlloc(length*sizeof(GUID)); // Not all may be used

    for(int i=0;i<length;++i)
    {
        if(PyWinObject_AsIID(PySequence_GetItem(result,i),pPages->pElems+pPages->cElems))
        {
            // Sucessfully converted, so put the next GUID in the next slot
            pPages->cElems++;
        }
        else
        {
            // Could not convert this GUID; ignore it and continue.
            PyErr_Clear();
        }
    }

	Py_DECREF(result);
	return hr;
}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:40,代码来源:PyISpecifyPropertyPages.cpp

示例12: PyArray_ConvertClipmodeSequence

/*NUMPY_API
 * Convert an object to an array of n NPY_CLIPMODE values.
 * This is intended to be used in functions where a different mode
 * could be applied to each axis, like in ravel_multi_index.
 */
NPY_NO_EXPORT int
PyArray_ConvertClipmodeSequence(PyObject *object, NPY_CLIPMODE *modes, int n)
{
    int i;
    /* Get the clip mode(s) */
    if (object && (PyTuple_Check(object) || PyList_Check(object))) {
        if (PySequence_Size(object) != n) {
            PyErr_Format(PyExc_ValueError,
                    "list of clipmodes has wrong length (%d instead of %d)",
                    (int)PySequence_Size(object), n);
            return NPY_FAIL;
        }

        for (i = 0; i < n; ++i) {
            PyObject *item = PySequence_GetItem(object, i);
            if(item == NULL) {
                return NPY_FAIL;
            }

            if(PyArray_ClipmodeConverter(item, &modes[i]) != NPY_SUCCEED) {
                Py_DECREF(item);
                return NPY_FAIL;
            }

            Py_DECREF(item);
        }
    }
    else if (PyArray_ClipmodeConverter(object, &modes[0]) == NPY_SUCCEED) {
        for (i = 1; i < n; ++i) {
            modes[i] = modes[0];
        }
    }
    else {
        return NPY_FAIL;
    }
    return NPY_SUCCEED;
}
开发者ID:alphaitis,项目名称:numpy,代码行数:42,代码来源:conversion_utils.c

示例13: read_list_float_attr

static double * read_list_float_attr(PyObject * record_obj, char * attr_name)
/* Read a list of floating point values from a Python record given the
 * attribute name and return a C list of doubles. The C list has to be
 * deallocated with free.
 */
{
  /* new reference */
  PyObject * item_list_obj = PyObject_GetAttrString(record_obj, attr_name);
  
  int num_item = (int) PySequence_Length(item_list_obj);
  
  double * retval = (double *) malloc(num_item * sizeof(double));

  int idx;
  
  for (idx = 0; idx < num_item; idx++)
  {
    /* new reference */
    PyObject * item_obj = PySequence_GetItem(item_list_obj, (Py_ssize_t) idx);

    retval[idx] = PyFloat_AsDouble(item_obj);

    Py_DECREF(item_obj);
  }
  
  Py_DECREF(item_list_obj);

#ifdef VERYVERBOSE
  printf(" %s = [", attr_name);
  for (idx = 0; idx < num_item; idx++)
    printf("%lf, ", retval[idx]);
  printf("]\n");
#endif

  return retval;
}
开发者ID:calonlay-hj,项目名称:ppaml-cp4,代码行数:36,代码来源:csolve.c

示例14: convertible

	static void* convertible(PyObject* obj_ptr){
		if(!PySequence_Check(obj_ptr)) return 0;
		bool isFlat=!PySequence_Check(py::handle<>(PySequence_GetItem(obj_ptr,0)).get());
		// mixed static/dynamic not handled (also not needed)
		BOOST_STATIC_ASSERT(
			(MT::RowsAtCompileTime!=Eigen::Dynamic && MT::ColsAtCompileTime!=Eigen::Dynamic)
			||
			(MT::RowsAtCompileTime==Eigen::Dynamic && MT::ColsAtCompileTime==Eigen::Dynamic)
		);
		int sz=PySequence_Size(obj_ptr);
		if(MT::RowsAtCompileTime!=Eigen::Dynamic){
			if(isFlat){
				// flat sequence (first item not sub-sequence), must contain exactly all items
				if(sz!=MT::RowsAtCompileTime*MT::ColsAtCompileTime) return 0;
			} else {
				// contains nested sequences, one per row
				if(sz!=MT::RowsAtCompileTime) return 0;
			}
		};
		return obj_ptr;
		// other checks done in the construct function
		// FIXME: it may be too late to do it there, as overloads are chosen based on *convertible*
		// (at least a clear message should be given when py::extract fails there)
	}
开发者ID:jbcolli2,项目名称:minieigen,代码行数:24,代码来源:converters.hpp

示例15: PySequence_GetItem

static PyObject *t_sequence_pop(t_sequence *self, PyObject *args)
{
    int index = -1, setDirty = 1;
    PyObject *value;

    if (!PyArg_ParseTuple(args, "|ii", &index, &setDirty))
        return NULL;

    value = PySequence_GetItem(self->sequence, index);
    if (!value)
        return NULL;

    if (!(self->itemvalue.flags & V_PURE))
    {
        PyObject *v = _restoreValue(self, value);
        Py_DECREF(value);
        
        if (!v)
            return NULL;
        value = v;
    }

    if (PySequence_DelItem(self->sequence, index) < 0)
    {
        Py_DECREF(value);
        return NULL;
    }

    if (setDirty && _t_itemvalue__setDirty((t_itemvalue *) self, 0) < 0)
    {
        Py_DECREF(value);
        return NULL;
    }

    return value;
}
开发者ID:HackLinux,项目名称:chandler,代码行数:36,代码来源:sequence.c


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