Files
RustPython/tests/snippets/stdlib_struct.py
2019-10-14 11:05:18 +09:00

25 lines
455 B
Python

import struct
data = struct.pack('IH', 14, 12)
assert data == bytes([14, 0, 0, 0, 12, 0])
v1, v2 = struct.unpack('IH', data)
assert v1 == 14
assert v2 == 12
data = struct.pack('<IH', 14, 12)
assert data == bytes([14, 0, 0, 0, 12, 0])
v1, v2 = struct.unpack('<IH', data)
assert v1 == 14
assert v2 == 12
data = struct.pack('>IH', 14, 12)
assert data == bytes([0, 0, 0, 14, 0, 12])
v1, v2 = struct.unpack('>IH', data)
assert v1 == 14
assert v2 == 12