import struct # 将数字转换为bytes类型 调用pack方法来统一表示要传输多少个字节,接收到之后,调用unpack方法解码为元组,告知需要接受多少位
ret = struct.pack('i',100000)
print(ret) # b'xa0x86x01x00'
print(struct.unpack('i',ret)) # (100000,)
ret = struct.pack('i',1)
print(ret) # b'x01x00x00x00'
ret = struct.pack('i',5)
print(ret) # b'x05x00x00x00'
ret = struct.pack('i',10)
print(ret) # b'
x00x00x00'
ret = struct.pack('i',50)
print(ret) # b'2x00x00x00'
ret = struct.pack('i',7863)
print(ret) # b'xb7x1ex00x00'
print(struct.unpack('i',ret)) # (7863,)