在python中使用结构和字符数组

2024-03-28 11:37:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是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

我是这里的新生。 谢谢你回答我的问题。你知道吗


Tags: 代码fields参数timevarctypestructure结构
1条回答
网友
1楼 · 发布于 2024-03-28 11:37:11

在Python中,字符串用引号括起来,如下所示:

 string = "this is a string"

这就是你所拥有的,当你需要字节的时候。 字节的定义如下:

bytes = b'this is a bytes object'

或者

bytes = b"This is another bytes object"

看起来你需要使用字节-所以在引号前加上'b'。你知道吗

相关问题 更多 >