title: Reading-in a binary JPEG-Header (in Python)
body: <p>I would like to read in a JPEG-Header and analyze it.
  According to <a href="https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_structure%20Wikipedia" rel="nofollow noreferrer">Wikipedia</a>, the header consists of a sequences of markers. Each Marker starts with <code>FF xx</code>, where <code>xx</code> is a specific Marker-ID.</p>
  
  <p>So my idea, was to simply read in the image in binary format, and seek for the corresponding character-combinations in the binary stream. This should enable me to split the header in the corresponding marker-fields.</p>
  
  <p>For instance, this is, what I receive, when I read in the first 20 bytes of an image:</p>
  
  <pre><code>binary_data = open('picture.jpg','rb').read(20)
  print(binary_data)
  </code></pre>
  
  <blockquote>
    <p>b'\xff\xd8\xff\xe1-\xfcExif\x00\x00MM\x00*\x00\x00\x00\x08'</p>
  </blockquote>
  
  <p>My questions are now:</p>
  
  <p>1) Why does python not return me nice chunks of 2 bytes (in hex-format).
  Somthing like this I would expect:
  <code>b'\xff \xd8 \xff \xe1 \x-' ... and so on</code>. Some blocks delimited by '\x' are much longer than 2 bytes.</p>
  
  <p>2) Why are there symbols like <code>-, M, *</code> in the returned string? Those are no characters of a hex representation I expect from a byte string (only: 0-9, a-f, I think).</p>
  
  <p>Both observations hinder me in writing a simple parser.
  <em>So ultimately my question summarizes to: 
  How do I properly read-in and parse a JPEG Header in Python?</em></p>