我是靠谱客的博主 勤恳墨镜,这篇文章主要介绍pythonctype_是否可以通过ctype引用传递python字符串?,现在分享给大家,希望可以做个参考。

Assigning a new value to instances of the pointer types c_char_p, c_wchar_p, and c_void_p changes the memory location they point to, not the contents of the memory block (of course not, because Python strings are immutable):>>> s = "Hello, World"

>>> c_s = c_char_p(s)

>>> print c_s

c_char_p('Hello, World')

>>> c_s.value = "Hi, there"

>>> print c_s

c_char_p('Hi, there')

>>> print s # first string is unchanged

Hello, World

>>>You should be careful, however, not to

pass them to functions expecting

pointers to mutable memory. If you

need mutable memory blocks, ctypes has

a create_string_buffer function which

creates these in various ways. The

current memory block contents can be

accessed (or changed) with the raw

property, if you want to access it as

NUL terminated string, use the string

property:

ctypes教程说。我从中得到的结论是,只有当函数使用const char*时,传入python字符串才是有效的。记住,它不会有空终止。

我建议无论如何使用create_string_buffer。

最后

以上就是勤恳墨镜最近收集整理的关于pythonctype_是否可以通过ctype引用传递python字符串?的全部内容,更多相关pythonctype_是否可以通过ctype引用传递python字符串内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部