From 1ad656eb37f498cab3b01b1b1862035b02074ab3 Mon Sep 17 00:00:00 2001 From: Silas Kraume Date: Sat, 7 Oct 2023 12:18:07 +0200 Subject: [PATCH] improved slicing parameter --- cat_win/cat.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cat_win/cat.py b/cat_win/cat.py index 1cadcce9..f3cb4d63 100644 --- a/cat_win/cat.py +++ b/cat_win/cat.py @@ -657,12 +657,14 @@ def edit_content(content: list, show_bytecode: bool, file_index: int = 0, if not show_bytecode: for arg, param in holder.args: if arg == ARGS_CUT: - try: - content = [(prefix, eval(repr(line) + param)) - for prefix, line in content] - except (SyntaxError, NameError, ValueError, ArithmeticError): - err_print('Error at operation: ', param) - return + slice_evals = [None, None, None] + for i, p_split in enumerate(param[1:-1].split(':')): + try: + slice_evals[i] = int(eval(p_split)) + except (SyntaxError, NameError, ValueError, ArithmeticError): + pass + content = [(prefix, line[slice_evals[0]:slice_evals[1]:slice_evals[2]]) + for prefix, line in content] for arg, param in holder.args: if arg == ARGS_ENDS: