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

C++ PyString_FromFormat函数代码示例

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

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



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

示例1: AMC_repr

static PyObject *
AMC_repr (AMC *motion)
{
	if (motion->name == NULL)
		return PyString_FromFormat ("[AMC]");
	return PyString_FromFormat ("[AMC \"%s\"]", motion->name);
}
开发者ID:mvanderkolff,项目名称:navi-misc,代码行数:7,代码来源:motion.c


示例2: PyCField_repr

static PyObject *
PyCField_repr(CFieldObject *self)
{
    PyObject *result;
    Py_ssize_t bits = self->size >> 16;
    Py_ssize_t size = self->size & 0xFFFF;
    const char *name;

    name = ((PyTypeObject *)self->proto)->tp_name;

    if (bits)
        result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
            "<Field type=%s, ofs=%d:%d, bits=%d>",
#else
            "<Field type=%s, ofs=%zd:%zd, bits=%zd>",
#endif
            name, self->offset, size, bits);
    else
        result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
            "<Field type=%s, ofs=%d, size=%d>",
#else
            "<Field type=%s, ofs=%zd, size=%zd>",
#endif
            name, self->offset, size);
    return result;
}
开发者ID:nanwu,项目名称:pyston,代码行数:28,代码来源:cfield.c


示例3: enum_repr

    static PyObject* enum_repr(PyObject* self_)
    {
        // XXX(bhy) Potentional memory leak here since PyObject_GetAttrString returns a new reference
        // const char *mod = PyString_AsString(PyObject_GetAttrString( self_, const_cast<char*>("__module__")));
        PyObject *mod = PyObject_GetAttrString( self_, "__module__");
        enum_object* self = downcast<enum_object>(self_);
        if (!self->name)
        {
            return
#if PY_VERSION_HEX >= 0x03000000
                PyUnicode_FromFormat("%S.%s(%ld)", mod, self_->ob_type->tp_name, PyLong_AsLong(self_));
#else
                PyString_FromFormat("%s.%s(%ld)", PyString_AsString(mod), self_->ob_type->tp_name, PyInt_AS_LONG(self_));
#endif
        }
        else
        {
            PyObject* name = self->name;
            if (name == 0)
                return 0;

            return
#if PY_VERSION_HEX >= 0x03000000
                PyUnicode_FromFormat("%S.%s.%S", mod, self_->ob_type->tp_name, name);
#else
                PyString_FromFormat("%s.%s.%s", 
                        PyString_AsString(mod), self_->ob_type->tp_name, PyString_AsString(name));
#endif
        }
    }
开发者ID:bk5115545,项目名称:omegalib,代码行数:30,代码来源:enum.cpp


示例4: DBusPythonLong_tp_repr

static PyObject *
DBusPythonLong_tp_repr(PyObject *self)
{
    PyObject *parent_repr = (PyLong_Type.tp_repr)(self);
    PyObject *vl_obj;
    PyObject *my_repr;
    long variant_level;

    if (!parent_repr) return NULL;
    vl_obj = PyObject_GetAttr(self, dbus_py_variant_level_const);
    if (!vl_obj) {
        Py_DECREF(parent_repr);
        return NULL;
    }
    variant_level = PyInt_AsLong(vl_obj);
    Py_DECREF(vl_obj);
    if (variant_level) {
        my_repr = PyString_FromFormat("%s(%s, variant_level=%ld)",
                                      self->ob_type->tp_name,
                                      PyString_AS_STRING(parent_repr),
                                      variant_level);
    }
    else {
        my_repr = PyString_FromFormat("%s(%s)", self->ob_type->tp_name,
                                      PyString_AS_STRING(parent_repr));
    }
    /* whether my_repr is NULL or not: */
    Py_DECREF(parent_repr);
    return my_repr;
}
开发者ID:mahomahomaho,项目名称:dbus-python-egg,代码行数:30,代码来源:abstract.c


示例5: normalizeUserObj

static PyObject *
normalizeUserObj(PyObject *obj)
{
	PyCFunctionObject *fn;
	if (!PyCFunction_Check(obj)) {
		Py_INCREF(obj);
		return obj;
	}
	/* Replace built-in function objects with a descriptive string
	   because of built-in methods -- keeping a reference to
	   __self__ is probably not a good idea. */
	fn = (PyCFunctionObject *)obj;

	if (fn->m_self == NULL) {
		/* built-in function: look up the module name */
		PyObject *mod = fn->m_module;
		char *modname;
		if (mod && PyString_Check(mod)) {
			modname = PyString_AS_STRING(mod);
		}
		else if (mod && PyModule_Check(mod)) {
			modname = PyModule_GetName(mod);
			if (modname == NULL) {
				PyErr_Clear();
				modname = "__builtin__";
			}
		}
		else {
			modname = "__builtin__";
		}
		if (strcmp(modname, "__builtin__") != 0)
			return PyString_FromFormat("<%s.%s>",
						   modname,
						   fn->m_ml->ml_name);
		else
			return PyString_FromFormat("<%s>",
						   fn->m_ml->ml_name);
	}
	else {
		/* built-in method: try to return
			repr(getattr(type(__self__), __name__))
		*/
		PyObject *self = fn->m_self;
		PyObject *name = PyString_FromString(fn->m_ml->ml_name);
		if (name != NULL) {
			PyObject *mo = _PyType_Lookup(Py_TYPE(self), name);
			Py_XINCREF(mo);
			Py_DECREF(name);
			if (mo != NULL) {
				PyObject *res = PyObject_Repr(mo);
				Py_DECREF(mo);
				if (res != NULL)
					return res;
			}
		}
		PyErr_Clear();
		return PyString_FromFormat("<built-in method %s>",
					   fn->m_ml->ml_name);
	}
}
开发者ID:1310701102,项目名称:sl4a,代码行数:60,代码来源:_lsprof.c


示例6: SqlType_repr

static PyObject* SqlType_repr(PyObject* self)
{
    const struct SqlType* type = (const struct SqlType*)self;
    PyObject* repr = NULL;

    bool include_size = (-1 != type->size);

#if PY_MAJOR_VERSION < 3
    /*
        Python2.6's implementation of `PyUnicode_FromFormat` is buggy and
        will crash when the '%R' format specifier is used. Additionally
        a conversion to the `str` type is required. Avoid all this in Python2.
    */
    PyObject* value = PyObject_Repr(type->value);
    if (value)
    {
        if (include_size)
        {
            repr = PyString_FromFormat(
                "%s(%s, size=%d)",
                Py_TYPE(self)->tp_name,
                PyString_AS_STRING(value),
                type->size
            );
        }
        else
        {
            repr = PyString_FromFormat(
                "%s(%s)",
                Py_TYPE(self)->tp_name,
                PyString_AS_STRING(value)
            );
        }
        Py_DECREF(value);
    }
#else /* if PY_MAJOR_VERSION < 3 */
    if (include_size)
    {
        repr = PyUnicode_FromFormat(
            "%s(%R, size=%d)",
            Py_TYPE(self)->tp_name,
            type->value,
            type->size
        );
    }
    else
    {
        repr = PyUnicode_FromFormat(
            "%s(%R)",
            Py_TYPE(self)->tp_name,
            type->value
        );
    }
#endif /* else if PY_MAJOR_VERSION < 3 */
    return repr;
}
开发者ID:zillow,项目名称:ctds,代码行数:56,代码来源:type.c


示例7: cell_repr

static PyObject *
cell_repr(PyCellObject *op)
{
	if (op->ob_ref == NULL)
		return PyString_FromFormat("<cell at %p: empty>", op);

	return PyString_FromFormat("<cell at %p: %.80s object at %p>",
				   op, op->ob_ref->ob_type->tp_name,
				   op->ob_ref);
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:10,代码来源:cellobject.c


示例8: PySwigPacked_str

SWIGRUNTIME PyObject *
PySwigPacked_str(PySwigPacked *v)
{
  char result[SWIG_BUFFER_SIZE];
  if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){
    return PyString_FromFormat("%s%s", result, v->desc);
  } else {
    return PyString_FromFormat("%s", v->desc);
  }  
}
开发者ID:Complex501,项目名称:visionegg,代码行数:10,代码来源:win32_getrefresh_wrap.c


示例9: meth_repr

static PyObject *
meth_repr(PyCFunctionObject *m)
{
    if (m->m_self == NULL)
        return PyString_FromFormat("<built-in function %s>",
                                   m->m_ml->ml_name);
    return PyString_FromFormat("<built-in method %s of %s object at %p>",
                               m->m_ml->ml_name,
                               m->m_self->ob_type->tp_name,
                               m->m_self);
}
开发者ID:0xcc,项目名称:python-read,代码行数:11,代码来源:methodobject.c


示例10: range_repr

static PyObject *
range_repr(range *self)
{
	if (self->step == 1)
	{
		return PyString_FromFormat("range(%i, %i)", self->start, self->stop);
	}
	else
	{
		return PyString_FromFormat("range(%i, %i, %i)", self->start, self->stop, self->step);
	}
}
开发者ID:Ansh191,项目名称:AMath,代码行数:12,代码来源:range.c


示例11: PyBlitzArray_repr

/* Representation */
static PyObject* PyBlitzArray_repr(PyBlitzArrayObject* o) {
  switch (o->ndim) {
    case 1:
      return
        PyString_FromFormat
          ("%s(%" PY_FORMAT_SIZE_T "d,'%s')",
          Py_TYPE(o)->tp_name,
          o->shape[0],
          PyBlitzArray_TypenumAsString(o->type_num)
          );
    case 2:
      return
        PyString_FromFormat
          ("%s((%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d),'%s')",
          Py_TYPE(o)->tp_name,
          o->shape[0],
          o->shape[1],
          PyBlitzArray_TypenumAsString(o->type_num)
          );
    case 3:
      return
        PyString_FromFormat
          ("%s((%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d),'%s')",
          Py_TYPE(o)->tp_name,
          o->shape[0],
          o->shape[1],
          o->shape[2],
          PyBlitzArray_TypenumAsString(o->type_num)
          );
    case 4:
      return
        PyString_FromFormat
          ("%s((%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d,%" PY_FORMAT_SIZE_T "d),'%s')",
          Py_TYPE(o)->tp_name,
          o->shape[0],
          o->shape[1],
          o->shape[2],
          o->shape[3],
          PyBlitzArray_TypenumAsString(o->type_num)
          );
    default:
      return
        PyString_FromFormat
          ("[unsupported] %s(@%" PY_FORMAT_SIZE_T "d,'%s') %" PY_FORMAT_SIZE_T "d elements>",
          Py_TYPE(o)->tp_name,
          o->ndim,
          PyBlitzArray_TypenumAsString(o->type_num),
          PyBlitzArray_len(o)
          );
  }
}
开发者ID:183amir,项目名称:bob.blitz,代码行数:52,代码来源:array.cpp


示例12: preparePreLink

static PyObject *
preparePreLink(const char *prelink) {
	int len;
	len = strlen(prelink);
	if (strstr(prelink, "?") != NULL) {
		if (prelink[len-1] != '?' && prelink[len-1] != '&') {
			return PyString_FromFormat("%s&", prelink);
		} else {
			return PyString_FromString(prelink);
		}
	} else {
		return PyString_FromFormat("%s?", prelink);
	}
}
开发者ID:vanng822,项目名称:pypagination,代码行数:14,代码来源:pagination.c


示例13: package_repr

static PyObject *
package_repr(_PackageObject *self)
{
    cr_Package *pkg = self->package;
    PyObject *repr;
    if (pkg) {
        repr = PyString_FromFormat("<createrepo_c.Package object id %s, %s>",
                                   (pkg->pkgId ? pkg->pkgId : "-"),
                                   (pkg->name  ? pkg->name  : "-"));
    } else {
       repr = PyString_FromFormat("<createrepo_c.Package object id -, ->");
    }
    return repr;
}
开发者ID:cottsay,项目名称:createrepo_c,代码行数:14,代码来源:package-py.c


示例14: meth_repr

static PyObject *
meth_repr(PythonQtSignalFunctionObject *f)
{
  if (f->m_self->ob_type == &PythonQtClassWrapper_Type) {
    PythonQtClassWrapper* self = (PythonQtClassWrapper*) f->m_self;
    return PyString_FromFormat("<unbound qt signal %s of %s type>",
      f->m_ml->slotName().data(),
      self->classInfo()->className());
  } else {
    return PyString_FromFormat("<qt signal %s of %s instance at %p>",
      f->m_ml->slotName().data(),
      f->m_self->ob_type->tp_name,
      f->m_self);
  }
}
开发者ID:CarloNicolini,项目名称:GraphInsight,代码行数:15,代码来源:PythonQtSignal.cpp


示例15: DiscoDBIter_str

static PyObject *
DiscoDBIter_str(DiscoDBIter *self)
{
    PyObject
        *string = PyString_FromFormat("%s(", Py_TYPE(self)->tp_name),
        *format = NULL;

    if (string == NULL)
        goto Done;

    if (Py_TYPE(self) == &DiscoDBIterItemType)
        format = PyString_FromString("('%s', %s)");
    else
        format = PyString_FromString("'%s'");

    if (format == NULL)
        goto Done;

    PyString_ConcatAndDel(&string, DiscoDBIter_format(self, format, 3));
    PyString_ConcatAndDel(&string, PyString_FromString(")"));

 Done:
    Py_CLEAR(format);

    if (PyErr_Occurred()) {
        Py_CLEAR(string);
        return NULL;
    }

    return string;
}
开发者ID:christofd,项目名称:disco,代码行数:31,代码来源:discodbmodule.c


示例16: mod_populate_vptuple

/*
 *	This is the core Python function that the others wrap around.
 *	Pass the value-pair print strings in a tuple.
 *
 *	FIXME: We're not checking the errors. If we have errors, what
 *	do we do?
 */
static int mod_populate_vptuple(PyObject *pPair, VALUE_PAIR *vp)
{
	PyObject *pStr = NULL;
	char buf[1024];
	
	/* Look at the vp_print_name? */
	
	if (vp->da->flags.has_tag)
		pStr = PyString_FromFormat("%s:%d", vp->da->name, vp->tag);
	else
		pStr = PyString_FromString(vp->da->name);
	
	if (!pStr)
		goto failed;
	
	PyTuple_SET_ITEM(pPair, 0, pStr);
	
	vp_prints_value(buf, sizeof(buf), vp, 1);
	
	if ((pStr = PyString_FromString(buf)) == NULL)
		goto failed;
	PyTuple_SET_ITEM(pPair, 1, pStr);
	
	return 0;
	
failed:
	return -1;
}
开发者ID:ehayon,项目名称:freeradius-server,代码行数:35,代码来源:rlm_python.c


示例17: igraphmodule_ARPACKOptions_str

/** \ingroup python_interface_arpack
 * \brief Formats an \c igraph.ARPACKOptions object in a
 * human-consumable format.
 * 
 * \return the formatted textual representation as a \c PyObject
 */
PyObject* igraphmodule_ARPACKOptions_str(
  igraphmodule_ARPACKOptionsObject *self) {
  PyObject *s;
  
  s=PyString_FromFormat("ARPACK parameters");
  return s;
}
开发者ID:CansenJIANG,项目名称:igraph,代码行数:13,代码来源:arpackobject.c


示例18: PySymbolicExpression_AsSymbolicExpression

static PyObject *SymbolicExpression_getComment(PyObject *self, PyObject *noarg) {
  SymbolicExpression *expression = PySymbolicExpression_AsSymbolicExpression(self);
  if (expression->getComment().empty() == false)
    return PyString_FromFormat("%s", expression->getComment().c_str());
  Py_INCREF(Py_None);
  return Py_None;
}
开发者ID:shenyanjun,项目名称:Triton,代码行数:7,代码来源:PySymbolicExpression.cpp


示例19: connection_repr

static PyObject *
connection_repr(connectionObject *self)
{
    return PyString_FromFormat(
        "<connection object at %p; dsn: '%s', closed: %ld>",
        self, (self->dsn ? self->dsn : "<unintialized>"), self->closed);
}
开发者ID:gencer,项目名称:psycopg2,代码行数:7,代码来源:connection_type.c


示例20: handle_core_message

void
handle_core_message(DBusMessage *bus_msg, const char *path, const char *iface, const char *method, const char *sender, PyObject *py_args)
{
    if (strcmp(method, "setLocale") == 0) {
        PyDict_SetItemString(PyDict_GetItemString(py_core, "locales"), sender, PyTuple_GetItem(py_args, 0));
        bus_reply_object(bus_msg, Py_True, "b");
    }
    else if (strcmp(method, "cancel") == 0) {
        log_debug("Cancel requested.\n");
        int i;
        int total = 0;
        // Iterate over all child processes
        for (i = 0; i < my_proc.nr_children; i++) {
            struct ProcChild *child = &my_proc.children[i];
            if (dbus_message_has_sender(child->bus_msg, sender)) {
                kill(child->pid, SIGINT);
                total++;
            }
        }
        log_debug("Killed %d processes.\n", total);
        bus_reply_object(bus_msg, PyInt_FromLong((long) total), "i");
    }
    else if (strcmp(method, "listRunning") == 0) {
        int i;
        PyObject *py_list = PyList_New(0);
        // Iterate over all child processes
        for (i = 0; i < my_proc.nr_children; i++) {
            struct ProcChild *child = &my_proc.children[i];
            if (PyTuple_GetItem(py_args, 0) == Py_True || dbus_message_has_sender(child->bus_msg, sender)) {
                PyList_Append(py_list, PyString_FromFormat("%s.%s", dbus_message_get_interface(child->bus_msg), dbus_message_get_member(child->bus_msg)));
            }
        }
        bus_reply_object(bus_msg, py_list, "as");
    }
}
开发者ID:Pardus-Linux,项目名称:COMAR,代码行数:35,代码来源:loop.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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