import struct total = 0 with open("/dev/zero") as f: for _ in xrange(1000): chunk = f.read(64 * 1024) if chunk == "": break for byte in chunk: i, = struct.unpack("B", byte) total += i total %= 256 print(total)