title: What is the equivalent of 'fread' from Matlab in Python?
body: <p>I have practically no knowledge of Matlab, and need to translate some parsing routines into Python. They are for large files, that are themselves divided into 'blocks', and I'm having difficulty right from the off with the checksum at the top of the file.</p>
  
  <p>What exactly is going on here in Matlab?</p>
  
  <pre><code>status = fseek(fid, 0, 'cof');
  fposition = ftell(fid);
  disp(' ');
  disp(['** Block ',num2str(iBlock),' File Position = ',int2str(fposition)]);
  
  % ----------------- Block Start ------------------ %
  [A, count] = fread(fid, 3, 'uint32');
  if(count == 3)
      magic_l = A(1);
      magic_h = A(2);
      block_length = A(3);
  else
      if(fposition == file_length)
          disp(['** End of file OK']);
      else
          disp(['** Cannot read block start magic !  Note File Length = ',num2str(file_length)]);
      end
      ok = 0;
      break;
  end
  </code></pre>
  
  <p>fid is the file currently being looked at
  iBlock is a counter for which 'block' you're in within the file</p>
  
  <p>magic_l and magic_h are to do with checksums later, here is the code for that (follows straight from the code above):</p>
  
  <pre><code>disp(sprintf('  Magic_L = %08X, Magic_H = %08X, Length = %i', magic_l, magic_h, block_length));
  correct_magic_l = hex2dec('4D445254');
  correct_magic_h = hex2dec('43494741');
  
  if(magic_l ~= correct_magic_l | magic_h ~= correct_magic_h)
      disp(['** Bad block start magic !']);
      ok = 0;
      return;
  end
  
  remaining_length = block_length - 3*4 - 3*4;   % We read Block Header, and we expect a footer
  disp(sprintf('  Remaining Block bytes = %i', remaining_length));
  </code></pre>
  
  <ul>
  <li>What is going on with the <code>%08X</code> and the <code>hex2dec</code> stuff? </li>
  <li>Also, why specify <code>3*4</code> instead of <code>12</code>?</li>
  </ul>
  
  <p>Really though, I want to know how to replicate <code>[A, count] = fread(fid, 3, 'uint32');</code> in Python, as <code>io.readline()</code> is just pulling the first 3 characters of the file. Apologies if I'm missing the point somewhere here. It's just that using <code>io.readline(3)</code> on the file seems to return something it shouldn't, and I don't understand how the <code>block_length</code> can fit in a single byte when it could potentially be very long.</p>
  
  <p>Thanks for reading this ramble. I hope you can understand kind of what I want to know! (Any insight at all is appreciated.)</p>