title: Read bytes from string in Python
body: <p>I have a python string representing bytes read from network, I need to read successively several bytes from this string. For example I have 9 bytes in a string, I need to read 4 bytes as integer, 2 bytes as short, and 3 bytes of custom data type. </p>
  
  <p>Is there a reader in python to do something like:</p>
  
  <pre><code>reader = reader(my_string)    
  
  integer = int.from_bytes(reader.read(4), 'big')
  short = int.from_bytes(reader.read(2), 'big')
  custom = customType.Unpack(reader.read(3))
  </code></pre>
  
  <p>I thought use struct.unpack, but I don't know how to handle non-primitive types. </p>
  
  <p>Any idea ?</p>
  
  <p>Thanks.</p>