In brief
struct.pack('>H', 258) produces the two bytes b'\x01\x02'. The > prefix selects big-endian order, while H describes an unsigned short integer in that format.
Useful to know
struct.pack('>H', 258) produces the two bytes b'\x01\x02'. The > prefix selects big-endian order, while H describes an unsigned short integer in that format. [1]
For network protocols, do not leave native machine layout as an implicit contract. Specify sizes and alignment. The same visible numbers can be stored differently under another format, so the recipient needs a compatible description.
Sources
For further detail and to check the information: