1. 装饰器带有参数(比如:retry)

import time


def call_out(timeout=0):
    def check_login(func):
        def wrapper(*args, **kwargs):
            print("-------1--------")
            time.sleep(timeout)
            ret = func(*args, **kwargs)
            print("--------2-----------")
            return ret
        return wrapper
    return check_login


@call_out(2)
def print_hello():
    print("hello world")
    return "ok"


print(print_hello())

2. 输出结果

C:\Users\HuJun\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/HuJun/PycharmProjects/pythonProject/daily_tesy/装饰器带有参数.py
-------1--------
hello world
--------2-----------
ok

Process finished with exit code 0