title: How to pack a dict into a struct so that I can store it in a file and later unpack it
body: <p>I have the following code to pack the dictionary into a struct ...</p>
  
  <pre><code>&gt;&gt;&gt; this = bytearray(2)    
  &gt;&gt;&gt; this[0] = 100   
  &gt;&gt;&gt; this[1] = 150  
  &gt;&gt;&gt; bool = True    
  &gt;&gt;&gt; str = 'new'  
  &gt;&gt;&gt; dct = {'bt_arr': this, 'string':str, 'boolean': bool}  
  &gt;&gt;&gt; print dct  
  {'bt_arr': bytearray(b'd\x96'), 'boolean': True, 'string': 'new'}  
  val = struct.pack ('!' + 'B' +'B' + 'B'*3 + '?', dct['bt_arr'][0], dct['bt_arr'][1],dct['string'][0:3], dct['boolean'])                                                                         
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  struct.error: pack requires exactly 6 arguments
  </code></pre>
  
  <p>can you kindly let me know what I'm doing wrong in the above code....</p>
  
  <p>I want to unpack it in a similar fashion....</p>