title: How to read bytes from file
body: <p>I'm trying to read the length of some metadata from a .lrf file. (Used with the program LoLReplay)</p>
  
  <p>There's not really documentation on these files, but I have already figured out how to do this in C++. I'm trying to re-write the project in python for multiple reasons, but I come across an error.</p>
  
  <p>To first explain, the .lrf file has metadata immediately at the start of the file in this format:</p>
  
  <ul>
  <li><p>first 4 bytes are for something I have no clue about.</p></li>
  <li><p>next 4 bytes store the length of the metadata in hexidecimal, up until the end of the metadata, which after is the actual contents of the replay.</p></li>
  <li><p>bytes after the initial 8 bytes are the metadata in json format</p></li>
  </ul>
  
  <p>The problem I'm having is actually reading the metadata length. This is the current function I have:</p>
  
  <pre><code>def getMetaLength(self):
      try:
          file = open(self.file,"r")
      except IOError:
          print ("Failed to open file.")
          file.close()
      #We need to skip the first 4 bytes.
      file.read(4)
      mdlength = file.read(4)
      print(hex(mdlength))
      file.close()
  </code></pre>
  
  <p>When I call this function, the shell returns a traceback stating:</p>
  
  <pre><code>    Traceback (most recent call last):
      File "C:\Users\Donald\python\lolcogs\lolcogs_main.py", line 6, in &lt;module&gt;
      lolcogs.getMetaLength()
      File "C:\Users\Donald\python\lolcogs\LoLCogs.py", line 20, in getMetaLength
      file.read(4)
      File "C:\Python32\lib\encodings\cp1252.py", line 23, in decode
      return codecs.charmap_decode(input,self.errors,decoding_table)[0]
      UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 3648:       character maps to &lt;undefined&gt;
  </code></pre>
  
  <p>My best guess is that read() is trying to read characters that are encoded in some unicode format, but these are definitely just bytes that I am attempting to read. Is there a way to read these as bytes? Also, is there a better way to skip bytes when you are attempting to read a file?</p>