如何将 ctypes 的 c_long 转换为 Python 的 int?

Posted

技术标签:

【中文标题】如何将 ctypes 的 c_long 转换为 Python 的 int?【英文标题】:How to convert ctypes' c_long to Python's int? 【发布时间】:2011-01-20 19:06:42 【问题描述】:

int(c_long(1)) 不起作用。

【问题讨论】:

【参考方案1】:
>>> ctypes.c_long(1).value
1

【讨论】:

【参考方案2】:

使用 c_long 对象的 'value' 属性。

c_long(1).value

i = c_long(1) print i.value

【讨论】:

【参考方案3】:
>>> type(ctypes.c_long(1).value)
<type 'int'>

【讨论】:

以上是关于如何将 ctypes 的 c_long 转换为 Python 的 int?的主要内容,如果未能解决你的问题,请参考以下文章

将 ctypes int** 转换为 numpy 二维数组

求VB数据类型转换函数

[转] python关于ctypes使用char指针与bytes相互转换的问题

将 ctype 字节数组转换为字节

在 python 中的 byref 向量参数上使用 ctypes 进行 DLL 转换

VB中如何将object类型转换为其他类型?