title: Ignore newline character in binary file with Python?
body: <p>I open my file like so :</p>
  
  <pre><code>f = open("filename.ext", "rb") # ensure binary reading with b
  </code></pre>
  
  <p>My first line of data looks like this (when using <code>f.readline()</code>):</p>
  
  <pre><code>'\x04\x00\x00\x00\x12\x00\x00\x00\x04\x00\x00\x00\xb4\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00:\x00\x00\x00;\x00\x00\x00&lt;\x00\x00\x007\x00\x00\x008\x00\x00\x009\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\t\x00\x00\x00\n'
  </code></pre>
  
  <p>Thing is, I want to read this data byte by byte (<code>f.read(4)</code>). While debugging, I realized that when it gets to the end of the first line, it still <strong>takes in the newline character <code>\n</code></strong> and it is used as the first byte of the following int I read. I don't want to simply use <code>.splitlines()</code>because some data could have an <code>n</code> inside and I don't want to corrupt it. I'm using Python 2.7.10, by the way. I also read that opening a binary file with the <code>b</code> parameter "takes care" of the new line/end of line characters; why is not the case with me?</p>
  
  <p>This is what happens in the console as the file's position is right before the newline character:</p>
  
  <pre><code>&gt;&gt;&gt; d = f.read(4)
  &gt;&gt;&gt; d
  '\n\x00\x00\x00'
  &gt;&gt;&gt; s = struct.unpack("i", d)
  &gt;&gt;&gt; s
  (10,)
  </code></pre>