title: How can I encode a 32bit integer into a byte array?
body: <p>I'm required to send a 32bit integer over a serial connection like so: <code>0xc6bf6f34</code> should become: <code>b'\xc6\xbf\x6f\x34'</code>.</p>
  
  <p>To that end, I created this, but, as always after such coding, I wondered if it's <em>pythonicism</em> could be improved with something in the standard libary:</p>
  
  <pre><code>def ltonlba(value):
      ''' ltonlba : Long to Network Long Byte Array '''
      from socket import htonl
      value = htonl(value)
      ba = b''
      for i in range(4):
              ba += chr((value) &amp; 0xff)
              value &gt;&gt;= 8
      return ba
  </code></pre>