Skip to content

Commit

Permalink
improved slicing parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Oct 7, 2023
1 parent 8641601 commit 1ad656e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cat_win/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1ad656e

Please sign in to comment.