Marcinの答えはおそらくあなたの質問に基づいて欲しいです.voracの答えには別の方法があります.
例:
import struct
import socket
s = socket.socket()
s.connect("127.0.0.1",5000) # connect to some TCP based network (and ignore any sort of endiness issues, which could be solved with other arguments to struct.pack)
data1 = 100
data2 = 200
data_packed = struct.pack("cc",chr(data1),chr(data2)) # pack 2 numbers as bytes (chars)
s.send(data_packed) # put it on the network as raw bytes
data_packed_out = s.recv(100) # get raw bytes from the network
data3,data4 = struct.unpack("cc",data_packed_out) # unpack said bytes