filePath = "input.txt" buffer = "Read buffer:\n" file = open(filePath, 'rU') while(1): bytes = file.read(5) if bytes: buffer += bytes else: break print buffer