I'm quite a newbie in Python and I want to speed up this method since it takes very long time especially when the size of the input file in Mbs. Also, I couldn't figure out how to use Cython in the for loop. I'm using this function with other functions to compare files byte by byte. Any recommendations?
# this function returns a file bytes in a list filename1 = 'doc1.pdf' def byte_target(filename1): f = open(filename1, "rb") try: b = f.read(1) tlist =  while True: # get file bytes t = ' '.join(format(ord(x), 'b') for x in b) b = f.read(1) if not b: break #add this byte to the list tlist.append(t) #print b finally: f.close() return tlist