>>> from ctypes import *
>>> c_int()
c_long(0)
>>> c_char_p(b'hello')
c_char_p(b'hello')>>> c_ushort(-5)
c_ushort(65531)
>>> seitz = c_char_p(b'loves the python')
>>> print(seitz)
c_char_p(b'loves the python')
>>> print(seitz.value)
b'loves the python'
最后一个演示样例将一个指向字符串'loves the python'的ctype指针赋给变量作值seutz.随后我们通过訪问seitz.value方法获取指针所指向的内容,我们称这个过程为解除引用(dereferencing)一个指针
未完待续...
未经作者允许不得转载
本文介绍了Python中ctypes模块的基本用法,包括如何使用ctypes创建不同类型的数据对象,并演示了如何处理字符串指针,如创建、赋值及解除引用等操作。
1686

被折叠的 条评论
为什么被折叠?



