'''Before'''
PATH1 = ...
PATH1_OUTPUT = ...
PATH2 = ...
PATH2_OUTPUT = ...
start = time.time()
print(f'Processing "{PATH1}"...')
xls1_content = read_excel(PATH1)
processed_content = process3(process2(process1(xls1_content)))
save_excel(processed_content, PATH1_OUTPUT)
print(f'Processing "{PATH1}" fininshed in {time.time() - start}s.')
start = time.time()
print(f'Processing "{PATH2}"...')
xls2_content = read_excel(PATH2)
processed_content = process3(process2(process1(xls2_content)))
save_excel(processed_content, PATH2_OUTPUT)
print(f'Processing "{PATH2}" fininshed in {time.time() - start}s.')
'''After'''
PATH1 = ...
PATH1_OUTPUT = ...
PATH2 = ...
PATH2_OUTPUT = ...
LOG1_FUNC = lambda path, _: f'Processing "{path}"'
LOG2_FUNC = lambda path, _: f'Processing "{path}" finished'
logged_process_excel = logged(process_excel, LOG1_FUNC, LOG2_FUNC)
logged_process_excel(PATH1, PATH1_OUTPUT)
logged_process_excel(PATH2, PATH2_OUTPUT)
def logged(func: Callable, log1_func: Callable, log2_func: Callable) -> Callable:
def new_func(*args, **kwargs):
start = time.time()
print(log1_func(*args, **kwargs))
result = func(*args, **kwargs)
print(f'{log2_func(*args, **kwargs)} in {time.time() - start}s.')
return result
return new_func
def process_excel(path: str, path_output: str) -> None:
content = read_excel(path)
processed_content = process_content(content)
save_excel(processed_content, path_output)
def process_content(content: str) -> str:
processed_content = process3(process2(process1(content)))
return processed_content