我遇到了ctypes的问题 . 我认为我的类型转换是正确的,错误对我没有意义 . “arg - ct.c_char_p(logfilepath)”行错误TypeError:预期的字节或整数地址而不是str实例
我试过python 3.5和3.4 .
功能我打电话:
stream_initialize('stream_log.txt')
Stream_initialize代码“
def stream_initialize(logfilepath):
f = shim.stream_initialize
arg = ct.c_char_p(logfilepath)
result = f(arg)
if result:
print(find_shim_error(result))
2 回答
c_char_p
需要bytes
对象,因此您必须先将string
转换为bytes
:另一种解决方案是使用
c_wchar_p
类型,它采用string
.为了完整起见:也可以将其称为
stream_initialize(b'stream_log.txt')
. 注意字符串前面的b
,这会导致它被解释为bytes
对象 .