我正在使用 ctype。我想使用结构作为参数。这是我的代码:
Time="AuditSuccess"
class SecurityVarToCdll(Structure):
_fields_ = [("Time",c_char_p),("EventID",c_char_p),("Keyword",c_char_p),("Level",c_int),("User",c_char_p)]
Var=SecurityVarToCdll()
Var.Time=c_type_p(Time)
然后我得到以下信息:
Var.Time = c_char_p(Time)
TypeError: bytes or integer address expected instead of str instance
我是这里的新生。 感谢您回答我的问题。
请您参考如下方法:
在 Python 中,字符串用引号括起来,如下所示:
string = "this is a string"
当您需要字节时,这就是您所拥有的。 字节定义如下:
bytes = b'this is a bytes object'
或
bytes = b"This is another bytes object"
看起来您需要使用字节 - 所以在引号前加上“b”。
