Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python struct.error:当我想使用struct.pack()时,struct格式的字符不正确_Python_Sockets_Struct_Pack - Fatal编程技术网

Python struct.error:当我想使用struct.pack()时,struct格式的字符不正确

Python struct.error:当我想使用struct.pack()时,struct格式的字符不正确,python,sockets,struct,pack,Python,Sockets,Struct,Pack,我想打包我的数据,用套接字发送 我做到了 sensor = b'cam' msg = struct.pack('3s >I >I', sensor, len(channel), len(inf_bytes)) + channel + inf_bytes ``` And the I got: struct.error: bad char in struct format Could you tell me where I am wrong? 只有格式字符串中的第一个字符可以>以

我想打包我的数据,用套接字发送

我做到了

sensor = b'cam' 
msg = struct.pack('3s >I >I', sensor, len(channel), len(inf_bytes)) + channel + inf_bytes ```


And the I got: struct.error: bad char in struct format
Could you tell me where I am wrong?

只有格式字符串中的第一个字符可以>以使用大端字符:

>>> struct.pack('3s>I>I', b'A', 2, 3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: bad char in struct format

>>> struct.pack('>3sII', b'A', 2, 3)
b'A\x00\x00\x00\x00\x00\x02\x00\x00\x00\x03'
结构包('3s>I>I',b'A',2,3) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 struct.error:struct格式的字符不正确 >>>结构包('>3sII',b'A',2,3) b'A\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x03' 医生说:(强调我的)

默认情况下,C类型以机器的本机格式和字节顺序表示,并在必要时通过跳过pad字节来正确对齐(根据C编译器使用的规则)。 或者,根据下表,格式字符串的第一个字符可用于指示压缩数据的字节顺序、大小和对齐方式: