Decorator factory
Section: Decorators and higher-order functions
Decorator factory
python
python
def retry(times: int):
def decorator(fn):
def wrapper(*args, **kwargs):
for _ in range(times):
try:
return fn(*args, **kwargs)
except Exception:
pass
return fn(*args, **kwargs)
return wrapper
return decoratorLearn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Decorators and higher-order functions