From ba4d33373d72fd2eb9e8b02b319f3ec17da4c698 Mon Sep 17 00:00:00 2001 From: Lavender Date: Tue, 16 Mar 2021 17:13:18 -0700 Subject: [PATCH] Fix the memory bug for real this time + calculate color changes correctly. --- pat.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pat.py b/pat.py index a534c9a..a452f07 100755 --- a/pat.py +++ b/pat.py @@ -26,20 +26,12 @@ if len(argv) == 1: for arg in argv[1:]: try: file = stdin if arg == "-" else open(arg, "r") - if file.seekable(): - file_length = file.seek(0, 2) - if file_length > bytes_to_read: - file.seek(file_length - bytes_to_read) - else: - file.seek(0) - read_result = file.read() - else: - read_result = file.read(bytes_to_read) + read_result = file.read(bytes_to_read) except Exception as e: print("Error reading %s: %s" % (file.name, e), file=stderr) continue - changes = len(list(filter(lambda c: not c in whitespace, read_result))) + changes = len(list(filter(lambda c: not c in whitespace, read_result))) - 1 step = 0 if changes == 0 else ColorInfo.AMOUNT / changes index = 0