【发布时间】:2021-07-04 01:26:15
【问题描述】:
我正在使用PyArg_Parsetuple 解析从python 发送的带有Y 格式说明符的字节数组。
Y (bytearray) [PyByteArrayObject *]
Requires that the Python object is a bytearray object, without attempting any conversion.
Raises TypeError if the object is not a bytearray object.
在 C 代码中我正在做:
static PyObject* py_write(PyObject* self, PyObject* args)
{
PyByteArrayObject* obj;
PyArg_ParseTuple(args, "Y", &obj);
.
.
.
python 脚本正在发送以下数据:
arr = bytearray()
arr.append(0x2)
arr.append(0x0)
如何在 C 中遍历 PyByteArrayObject*?打印 2 和 0?
谢谢。
【问题讨论】:
-
你看过
PyByteArrayObject的声明了吗? -
@AKX 谢谢找不到这个链接。希望现在能够这样做并回答我的问题。
标签: python c python-3.x