python装饰器之日志输出
作者:YXN-python 阅读量:72 发布日期:2023-02-28
日志输出:
def log_results(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
with open("results.log", "a") as log_file:
log_file.write(f"执行{func.__name__}函数 - 返回值: {result}\n")
return result
return wrapper
@log_results
def calculate_metrics(data):
# Your metric calculation code here
return data
YXN-python
2023-02-28