2024-10-06 12:32:22 发布
网友
在python文档中,我有两个关于struct的问题:
struct
Byte Order, Size, and Alignment:对于网络通信,我应该使用!而不是{}? 例如:struct.pack("!BBH", 1, 12, 512)还是{}?在
!
struct.pack("!BBH", 1, 12, 512)
Format characters:无符号int(I)和unsigned long(L)之间有什么区别,因为它们都是4字节?在
感谢您抽出时间,如果这是一个愚蠢的问题,请原谅我:-)
如果您希望您的代码在任何地方运行都能产生相同的输出,那么您为什么要使用=?所以当然,是的,你应该使用一个对每个人都有相同意义的代码。标准是!,所以使用!。在
=
阅读格式代码表上方的标题:
The ‘Standard size’ column refers to the size of the packed value in bytes when using standard size; that is, when the format string starts with one of '<', '>', '!' or '='. When using native size, the size of the packed value is platform-dependent.
因此,如果使用@格式代码或省略格式代码,I的大小和{}的大小理论上可能不同,这取决于您的平台。在
@
I
如果您希望您的代码在任何地方运行都能产生相同的输出,那么您为什么要使用
=
?所以当然,是的,你应该使用一个对每个人都有相同意义的代码。标准是!
,所以使用!
。在阅读格式代码表上方的标题:
因此,如果使用}的大小理论上可能不同,这取决于您的平台。在
@
格式代码或省略格式代码,I
的大小和{相关问题 更多 >
编程相关推荐