Easiest way to "fill" payload?
<p>I wan't to send a UDP packet with a arbitrary packet size depending on my input argument, so whenever my "data" is not enough to fill up the wanted packet payload I want to just "fill" the rest with empty data.</p>

<p>So if I send <code>123</code> but I want the packet to be of size 100 bytes, the method will pad the packet with the access data, I don't want to iterate and add spaces to fill it out manually. </p>

<p>Any tips?</p>

<p>You could create a padding <code>bytearray()</code>, and just prepend (or append) it to your payload:</p>

<pre><code>payload = b'123'
padding_length = 100 - len(payload)
padding_byte = b' '
return bytearray(padding_byte * padding_length) + payload
</code></pre>

python sockets udp scapy