Home Tools Prompts Python Custom Decorator Builder
Coding intermediate Featured

Python Custom Decorator Builder

Writes custom Python function decorators for execution timing and logging.

Works with: all
Prompt
Act as a senior Python software engineer. Write a custom function decorator in Python for measuring execution time and logging parameters of [TARGET_FUNCTION]. Include functools.wraps preservation.
Example Output
python
import time
import functools

def time_logger(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start = time.perf_counter()
result = func(*args, **kwargs)
print(f"{func.__name__} executed in {time.perf_counter() - start:.4f}s")
return result
return wrapper
#python #decorators #coding #performance