void什么意思python,转换Python对象到C void类型

How can I convert Python object to C void type using Cython?

Currently I am getting this message when I try to cast

Casting temporary Python object to non-numeric non-Python type

解决方案

This can be done like this :

1. Cast from Python to C

If you really meant void * this would be :

some_pyobj = "abc"

cdef void *ptr

ptr = some_pyobj

If you meant PyObject * this would be :

cdef PyObject *ptr

ptr = some_pyobj # Cast from Python object to C pointer

Then, from C side, the PyObject struct is available by including Python.h.

Here is the reference (from object.h Python include file) :

/* Nothing is actually declared to be a PyObject, but every pointer to

* a Python object can be cast to a PyObject*. This is inheritance built

* by hand. Similarly every pointer to a variable-size Python object can,

* in addition, be cast to PyVarObject*.

*/

typedef struct _object {

PyObject_HEAD

} PyObject;

2. Cast from C to Python

It works in both ways, meaning that the following is also possible :

cdef PyObject *ptr

ptr = some_pyobj

cdef object some_other_pyobj

some_other_pyobj = ptr # Cast from C pointer to Python object

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值