python struct pack with space padding
Question: I need to create/send binary data in python using a given protocol. The
protocol calls for fixed width fields , with space padding thrown in. Using
python's struct.pack, the only thing I can think of is, calculating the space
padding and adding it in myself. Is there a better way to achieve this?

thanks


Answer: struct has a [placeholder](http://docs.python.org/library/struct.html#format-
strings) (`x`) for a padding byte you can use:

    
    
     # pack 2 16 bit values plus one pad byte
     from struct import pack
     packedStrWithOneBytePad = pack("hhx", 1000, 2000)
    

