def read_blocks(file_obj, size):
    while True:
        data = file_obj.read(size)
if not data:
    break
yield data
for block in read_blocks(file_obj, 4):
    use(block)
Как зациклиться до EOF в Python?