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

C++ PyDict_Keys函数代码示例

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

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



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

示例1: _scrap_get_types

/*
 * Gets the currently available types from the active clipboard.
 */
static PyObject*
_scrap_get_types (PyObject *self, PyObject *args)
{
    int i = 0;
    char **types;
    PyObject *list;
    PyObject *tmp;
    
    PYGAME_SCRAP_INIT_CHECK ();
    if (!pygame_scrap_lost ())
    {
        switch (_currentmode)
        {
        case SCRAP_SELECTION:
            return PyDict_Keys (_selectiondata);
        case SCRAP_CLIPBOARD:
        default:
            return PyDict_Keys (_clipdata);
        }
    }

    list = PyList_New (0);
    types = pygame_scrap_get_types ();
    if (!types)
        return list;
    while (types[i] != NULL)
    {
        tmp = PyString_FromString (types[i]);
        PyList_Append (list, tmp);
        Py_DECREF (tmp);
        i++;
    }
    return list;
}
开发者ID:ab3,项目名称:pygame-mirror,代码行数:37,代码来源:scrap.c


示例2: castToPyObject

configParserStruct::pythonParser::containerForVariables configParserStruct::pythonParser::listOfVariables( void *Object )
{
  containerForVariables Result;
  
  if ( Object == NULL )
    return Result;

  PyObject *Dict = castToPyObject(Object);

  if ( ! PyDict_Check( Dict ) )
    return Result;

  PyObject *KeysList = PyDict_Keys( Dict );
  Py_ssize_t KeysListSize = PyList_Size( KeysList );

  for ( ptrdiff_t Index = 0; Index < static_cast<ptrdiff_t>(KeysListSize); Index++ )
  {
    PyObject *Key = PyList_GetItem( KeysList, Index );
    PyObject *KeyRepr = PyObject_Repr( Key );
    std::string KeyString = dequoteString( PyString_AsString( KeyRepr ), "'" );
    PyObject *Item = PyDict_GetItem( Dict, Key );
    if ( PyDict_Check(Item) )
    {
      containerForVariables ListOfItemsinSubDict = listOfVariables( Item );
      for ( containerForVariables::const_iterator i = ListOfItemsinSubDict.begin(); i != ListOfItemsinSubDict.end(); ++i )
        Result.insert( KeyString + structSeparator() + *i );
    } else {
      Result.insert( KeyString );
    } 
  }

  return Result;
}
开发者ID:EKhilkevitch,项目名称:configParserStruct,代码行数:33,代码来源:pythonparser.cpp


示例3: checkDictKeys

//----------------------------------------------------------------------------
// Return set(dict.keys()).issubset(set([vkeys, ...])
// keys of dict must be string or unicode in Py2 and string in Py3!
// Parameters:
// dict - the Python dictionary object to be checked
// vkeys - a null-terminated list of keys (char *)
//----------------------------------------------------------------------------
int checkDictKeys(PyObject *dict, const char *vkeys, ...)
{
    int i, j, rc;
    PyObject *dkeys = PyDict_Keys(dict);              // = dict.keys()
    if (!dkeys) return 0;                             // no valid dictionary
    j = PySequence_Size(dkeys);                       // len(dict.keys())
    PyObject *validkeys = PyList_New(0);              // make list of valid keys
    va_list ap;                                       // def var arg list
    va_start(ap, vkeys);                              // start of args
    while (vkeys != 0)                                // reached end yet?
        { // build list of valid keys to check against
#if PY_MAJOR_VERSION < 3
        PyList_Append(validkeys, PyBytes_FromString(vkeys));    // Python 2
#else
        PyList_Append(validkeys, PyUnicode_FromString(vkeys));  // python 3
#endif
        vkeys = va_arg(ap, const char *);             // get next char string
        }
    va_end(ap);                                       // end the var args loop
    rc = 1;                                           // prepare for success
    for (i = 0; i < j; i++)
    {   // loop through dictionary keys
        if (!PySequence_Contains(validkeys, PySequence_GetItem(dkeys, i)))
            {
            rc = 0;
            break;
            }
    }
    Py_DECREF(validkeys);
    Py_DECREF(dkeys);
    return rc;
}
开发者ID:bhramoss,项目名称:code,代码行数:39,代码来源:recipe-580799.c


示例4: dump_ret_msg

/**
 * parse the return PyObject and store the result into task_ret_pool
 */
static void
dump_ret_msg(PyObject *pRet)
{
    if ( pRet == NULL) {
        throw std::runtime_error("pycall failed");
    }
    char *ret_err_msg;
    int rsize = PyDict_Size(pRet);
    int taskid;
    download_ret_t dr_ret;                  // down return mesg structure 
    PyObject *pret_keys_list = PyDict_Keys(pRet);
    pthread_mutex_lock(&retmtx);
    for (int i = 0; i < rsize; i++) {
        PyObject *pkey_item = PyList_GetItem(pret_keys_list, i);
        PyObject *pvalue_tuple = PyDict_GetItem(pRet, pkey_item);
        PyObject *pret_flag = PyTuple_GetItem(pvalue_tuple, 0);
        PyObject *perr_msg = PyTuple_GetItem(pvalue_tuple, 1);
        taskid = PyInt_AsLong(pkey_item);
        dr_ret.ret_flag = PyInt_AsLong(pret_flag);
        ret_err_msg = PyString_AsString(perr_msg);
        strncpy(dr_ret.err_msg, ret_err_msg, NAME_LEN);
        task_ret_pool[taskid] = dr_ret;
    }
    pthread_mutex_unlock(&retmtx);
}
开发者ID:colin-zhou,项目名称:reserve,代码行数:28,代码来源:download.cpp


示例5: PyDict_Keys

std::map<std::string, std::string> PythonTools::dtom( PyObject* d )
{
    std::map<std::string, std::string> results;
    if ( d != NULL && PyDict_Check( d ) )
    {
        PyObject* keyList = PyDict_Keys( d );
        PyObject* curKey;
        PyObject* curVal;
        for ( int i = 0; i < PyList_Size( keyList ); i++ )
        {
            curKey = PyList_GetItem( keyList, i );
            curVal = PyDict_GetItem( d, curKey );
            char* valstr = PyString_AsString( curVal );
            if ( valstr == NULL )
                gravUtil::logWarning( "PythonTools::dtom(): "
                        "value not a string\n" );
            char* keystr = PyString_AsString( curKey );
            if ( keystr == NULL )
                gravUtil::logWarning( "PythonTools::dtom(): "
                        "key not a string\n" );
            if ( keystr != NULL && valstr != NULL )
                results[ keystr ] = valstr;
        }
    }
    return results;
}
开发者ID:Adhesion,项目名称:grav,代码行数:26,代码来源:PythonTools.cpp


示例6: resulttuple_dir

/**
 * Extends __dir__ with the extra attributes accessible through
 * resulttuple_getattro()
 */
static PyObject *
resulttuple_dir(PyObject *self)
{
    PyObject *mapping_attr;
    PyObject *items = NULL;
    PyObject *mapping = NULL;
    PyObject *mapping_values = NULL;
    PyObject *result = NULL;

    mapping_attr = PYGLIB_PyUnicode_FromString (tuple_indices_key);
    mapping = PyTuple_Type.tp_getattro (self, mapping_attr);
    Py_DECREF (mapping_attr);
    if (mapping == NULL)
        goto error;
    items = PyObject_Dir ((PyObject*)self->ob_type);
    if (items == NULL)
        goto error;
    mapping_values = PyDict_Keys (mapping);
    if (mapping_values == NULL)
        goto error;
    result = PySequence_InPlaceConcat (items, mapping_values);

error:
    Py_XDECREF (items);
    Py_XDECREF (mapping);
    Py_XDECREF (mapping_values);

    return result;
}
开发者ID:Distrotech,项目名称:pygobject,代码行数:33,代码来源:pygi-resulttuple.c


示例7: dictkeys

int
dictkeys(const int handle)
{
    PyObject *v;
    PyObject *obj = getObjectFromHandle(handle);
    v = PyDict_Keys(obj);
    return newHandle(v);
}
开发者ID:monnerat,项目名称:iseriespython,代码行数:8,代码来源:i5pgm_old.c


示例8: PyErr_NoMemory

static char *build_headers_string(PyObject *dict)
{
    Py_ssize_t i, dict_len, buf_pos, buf_size, req_space, free_space;
    PyObject *keys, *key_ob;
    char *key, *value, *header_s;
    const char *header_format = "%s: %s\r\n";
    buf_size = 512;
    buf_pos = 0;
    if ((header_s = (char *) malloc(buf_size * sizeof(char))) == NULL) {
        PyErr_NoMemory();
        return NULL;
    }
    if (dict == NULL || dict == Py_None) {
        sprintf(header_s, "%s", "");
        return header_s;
    }
    if (!PyDict_Check(dict)) {
        PyErr_SetString(PyExc_TypeError, "Headers must be a dict");
        return NULL;
    }

    memset(header_s, '\0', (size_t) buf_size);
    if ((keys = PyDict_Keys(dict)) == NULL) {
        PyErr_SetString(PyExc_TypeError, "Key must not be null.");
        free(header_s);
        return NULL;
    }
    dict_len = PyList_Size(keys);
    for (i = 0; i < dict_len; ++i) {
        key_ob = PyList_GetItem(keys, i);
        if ((key = PyString_AsString(key_ob)) == NULL) {
            free(header_s);
            return NULL;
        }
        if ((value = PyString_AsString(PyDict_GetItem(dict, key_ob))) == NULL) {
            free(header_s);
            return NULL;
        }

        //Make sure header_s has enough space
        req_space = strlen(key) + strlen(value) + strlen(header_format);
        free_space = buf_size - buf_pos;
        while ((req_space + 1) > free_space) {  // +1 to be sure final '\0' fits
            if ((header_s = (char *) realloc(header_s, buf_size * 2)) == NULL) {
                PyErr_NoMemory();
                free(header_s);
                return NULL;
            }
            buf_size *= 2;
            free_space = buf_size - buf_pos;
        }
        sprintf(header_s + buf_pos, header_format, key, value);
        buf_pos += req_space;
    }
    header_s[buf_pos + 1] = '\0';
    return header_s;
}
开发者ID:mjwolf,项目名称:httplib,代码行数:57,代码来源:archonhttpmodule.c


示例9: print_dict

static void print_dict(PyObject *dict) {
	PyObject *keys = PyDict_Keys(dict);
	for (Py_ssize_t i = 0; i < PyList_Size(keys); ++i) {
		PyObject *key = PyList_GetItem(keys, i);
		debug("\t%s", PyUnicode_AsUTF8(key));
		Py_DECREF(key);
	}
	Py_DECREF(keys);
}
开发者ID:mtu-most,项目名称:franklin,代码行数:9,代码来源:module.cpp


示例10: py2c

 static std::map<K,V> py2c(PyObject * ob) {
   pyref keys = PyDict_Keys(ob);
   pyref values = PyDict_Values(ob);
   std::map<K,V> res;
   int len = PyDict_Size(ob);
   for (int i = 0; i < len; i++)
     res.emplace(py_converter<K>::py2c(PyList_GET_ITEM((PyObject*)keys, i)),  //borrowed ref
                 py_converter<V>::py2c(PyList_GET_ITEM((PyObject*)values, i))); //borrowed ref
   return res;
 }
开发者ID:JaksaVucicevic,项目名称:triqs,代码行数:10,代码来源:map.hpp


示例11: printDict

void printDict(PyObject* obj) {  
	if (!PyDict_Check(obj))  
		return;  
	PyObject *k, *keys;  
	keys = PyDict_Keys(obj);  
	for (int i = 0; i < PyList_GET_SIZE(keys); i++) {  
		k = PyList_GET_ITEM(keys, i);  
		char* c_name = PyString_AsString(k);  
		printf("%s\n", c_name);  
	}  
}  
开发者ID:hpzhong,项目名称:tyd,代码行数:11,代码来源:cpp.cpp


示例12: printDict

void printDict(PyObject* obj) {
	if (!PyDict_Check(obj))
		return;
	PyObject *k, *keys;
	keys = PyDict_Keys(obj);// get keys of the dictionary,list output
	for (int i = 0; i < PyList_GET_SIZE(keys); i++) {
		k = PyList_GET_ITEM(keys, i);
		char* c_name = PyString_AsString(k);
		printf("%s/n", c_name);
	}
}
开发者ID:chenxianpao,项目名称:Template,代码行数:11,代码来源:main.cpp


示例13: list

list dict_base::keys() const
{
    if (check_exact(this))
    {
        return list(detail::new_reference(
                        PyDict_Keys(this->ptr())));
    }
    else
    {
        return assume_list(this->attr("keys")());
    }
}
开发者ID:NeoAnomaly,项目名称:xray,代码行数:12,代码来源:dict.cpp


示例14: py_set_colormap

static PyObject* py_set_colormap(PyObject *self, PyObject *args,
                                 PyObject *kwargs) {

  const char *kwnames[] = {"name", "pairs", NULL};
  PyObject *newdict, *keys, *vals;
  PyObject *result = NULL;
  VMDApp *app;
  char *name;

  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO!:color.set_colormap",
                                   (char**) kwnames, &name, &PyDict_Type,
                                   &newdict))
    return NULL;

  if (!(app = get_vmdapp()))
    return NULL;

  keys = PyDict_Keys(newdict);
  vals = PyDict_Values(newdict);

  for (int i=0; i<PyList_Size(keys); i++) {
    char *keyname = as_charptr(PyList_GetItem(keys, i));
    char *valname = as_charptr(PyList_GetItem(vals, i));

    if (!keyname || !valname || PyErr_Occurred()) {
      PyErr_SetString(PyExc_ValueError, "set_colormap dictionary invalid");
      goto cleanup;
    }

    if (!app->color_change_name(name, keyname, valname)) {
      PyErr_SetString(PyExc_ValueError,
                      "Invalid color category or item specified");
      goto cleanup;
    }
  }
  result = Py_None;

  // Getting the keys and values from the dictionary makes a new reference.
  // We tell Python we're done with it so as to not leak memory.
  // This needs to happen even if there was a problem setting color, which is
  // why we don't return NULL from the error checking statements above.
cleanup:
  Py_DECREF(keys);
  Py_DECREF(vals);

  Py_XINCREF(result);
  return result;
}
开发者ID:Eigenstate,项目名称:vmd-python,代码行数:48,代码来源:py_color.C


示例15: ops

//=============================================================================
// METHOD: SPELLconfigDict::reset()
//=============================================================================
void SPELLconfigDict::reset( PyObject* dict )
{
	m_values.clear();
	if (dict)
	{
		SPELLsafePythonOperations ops ("SPELLconfigDict::reset()");
		SPELLpyHandle keys = PyDict_Keys(dict);
		unsigned int numKeys = PyList_Size(keys.get());
		for( unsigned int idx = 0; idx < numKeys; idx++ )
		{
			PyObject* key = PyList_GetItem( keys.get(), idx );
			PyObject* value = PyDict_GetItem( dict, key );
			m_values.insert( std::make_pair( PYSSTR(key), SPELLpyValue(value) ));
		}
	}
}
开发者ID:Spacecraft-Code,项目名称:SPELL,代码行数:19,代码来源:SPELLconfigDict.C


示例16: PyDict_New

 /*static PyObject * c2py(std::map<K,V> &m) {
  PyObject * d = PyDict_New();
  for (auto & x : m) {
   pyref k = py_converter<K>::c2py(x.first);
   pyref v = py_converter<V>::c2py(x.second);   
   if (PyDict_SetItem(d,k,v) == -1) { Py_DECREF(d); return NULL;} // error
  }
  return d;
 }*/
 static bool is_convertible(PyObject *ob, bool raise_exception) {
  if (!PyDict_Check(ob)) goto _false;
  {
   pyref keys = PyDict_Keys(ob);
   pyref values = PyDict_Values(ob);
   int len = PyDict_Size(ob);
   for (int i = 0; i < len; i++) {
     if (!py_converter<K>::is_convertible(PyList_GET_ITEM((PyObject*)keys, i),raise_exception)) goto _false; //borrowed ref
     if (!py_converter<V>::is_convertible(PyList_GET_ITEM((PyObject*)values, i),raise_exception)) goto _false; //borrowed ref
   }
   return true;
  }
  _false:
  if (raise_exception) { PyErr_SetString(PyExc_TypeError, "Cannot convert to std::map");}
  return false;
 }
开发者ID:JaksaVucicevic,项目名称:triqs,代码行数:25,代码来源:map.hpp


示例17: FormatsRepr

// ----------------------------------------------------------------
static PyObject *
FormatsRepr(PyFormatsObject *cFormats)
{
	char sBuf[ 1000 ];
	int i;
	PyObject* cTmp= PyDict_Keys( FormatsType.tp_dict );
	sBuf[ 0 ]= '\0';
	for( i= 0; i< PyObject_Length( cTmp ); i++ )
	{
		char *s= PyString_AsString( PyList_GetItem( cTmp, i ));
		if( strlen( s )> 2 && ( s[ 0 ]== s[ 1 ] ) && ( s[ 1 ]== '_' ) )
			continue;
		if( i )
			strcat( sBuf, ",");
		strcat( sBuf, s);
	}
	return PyString_FromString( sBuf );
}
开发者ID:audioburn,项目名称:pymedia-redux-full,代码行数:19,代码来源:vcodec.c


示例18: PyDict_Keys

/* Convert the set of state numbers into a sorted tuple for use as a
 * dictionary key.
 */
static PyObject *make_key(PyObject *state_set)
{
  PyObject *states, *key;

  states = PyDict_Keys(state_set);
  if (states == NULL) {
    return NULL;
  }
  if (PyList_Sort(states) < 0) {
    Py_DECREF(states);
    return NULL;
  }
  key = PySequence_Tuple(states);
  Py_DECREF(states);
  if (key == NULL) {
    return NULL;
  }
  return key;
}
开发者ID:H1d3r,项目名称:binary_blobs,代码行数:22,代码来源:content_model.c


示例19: get_vmdapp

static PyObject *set_colors(PyObject *self, PyObject *args) {
  PyObject *newdict;
  if (!PyArg_ParseTuple(args, (char *)"O!", &PyDict_Type, &newdict))
    return NULL;

  VMDApp *app = get_vmdapp();
  PyObject *keys = PyDict_Keys(newdict);
  PyObject *vals = PyDict_Values(newdict);
  int error = 0;
  for (int i=0; i<PyList_Size(keys); i++) {
    char *keyname = PyString_AsString(PyList_GET_ITEM(keys, i));
    if (PyErr_Occurred()) {
      error = 1;
      break;
    }
    if (app->color_index(keyname) < 0) {
      PyErr_SetString(PyExc_ValueError, (char *)"Unknown color");
      error = 1;
      break;
    }
    PyObject *newtuple = PyList_GET_ITEM(vals, i);
    if (!PyTuple_Check(newtuple) || PyTuple_Size(newtuple) != 3) {
      PyErr_SetString(PyExc_ValueError, (char *)"color definition must be 3-tuple of floats");
      error = 1;
      break;
    }
    float rgb[3];
    for (int j=0; j<3; j++) 
      rgb[j] = (float)PyFloat_AsDouble(PyTuple_GET_ITEM(newtuple, j));
    if (PyErr_Occurred()) {
      error = 1;
      break;
    }
    app->color_changevalue(keyname, rgb[0], rgb[1], rgb[2]);
  }
  Py_DECREF(keys);
  Py_DECREF(vals);
  if (error)
    return NULL;

  Py_INCREF(Py_None);
  return Py_None;
}
开发者ID:gzoppetti,项目名称:ExscitechVmd,代码行数:43,代码来源:py_color.C


示例20: print_dict

void print_dict(PyObject *d)
{
    PyObject *k;
    Py_ssize_t size, i =0;


    k = PyDict_Keys(d);

    size = PyList_Size(k);

    printf("Size : %d\n", size);
    for (i = 0; i < size; i++) {
        PyObject *item = PyList_GET_ITEM(k, i);
#ifndef IS_PY3K
        printf("-- %s -- \n", PyString_AsString(item));
#else
		printf("-- %s -- \n", PyUnicode_AsUTF8String(item));
#endif
	}


}
开发者ID:leishen,项目名称:Pybag,代码行数:22,代码来源:exceptions.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PyDict_SetItem函数代码示例发布时间:2022-05-30
下一篇:
C++ PyDict_GetItem函数代码示例发布时间: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