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 decorator

Learn 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
Simple decorator
Simple decorator
OpenIn sheetpythonsame section
Map over data
Map over data
OpenIn sheetpythonsame section
Filter data
Filter data
OpenIn sheetpythonsame section
Reduce values
Reduce values
OpenIn sheetpythonsame section
Partial function
Partial function
OpenIn sheetpythonsame section
Define a function
Define a function