Q:

Byte Level Manipulation in Python

I have designed a compression algorithm that operates on the byte level representation of a file.
I want to do the following procedure:
Read k bytes from
Run algorithm on byte array of size k outputting compressed material
Write compressed material to a new file
Repeat until file is exhausted.
How do I read the first k bytes of a file? 
Furthermore I want these bytes to be in binary format. I noticed that python automatically convert bytes into string character when I use the open('filename', 'rb') method, I want to actually see the bytes in the form of (0101101) and not as an integer, string, etc...
Then I want to directly write, in this binary format, to a new file.

A:

I noticed that python automatically convert bytes into string character when I use the open('filename', 'rb') method

It is incorrect. open('filename', 'rb').read(k) returns upto k bytes from the file. The value is a bytes object. You can print it in the binary ("01") format. See Convert Binary to ASCII and vice versa (Python).
You can write the read bytes object to a new file as is:
open('output', 'wb').write(bytes_object)

There is no conversion of any kind (no '\n' -> '\r\n', no decoding/encoding using a character encoding -- nothing).

