Passing parameters to decorator at runtime

前端 未结 2 2078
闹比i
闹比i 2021-01-12 08:08

If I create a python decorator function like this

def retry_until_true(tries, delay=60):
    \"\"\"
    Decorator to rety a function or method until it retur         


        
2条回答
  •  感动是毒
    2021-01-12 08:34

    Sure you can, just nest your function definition in another function, for example:

    def explicit_setup_func(tries, delay=60):
        @retry_until_true(tries, delay)
        def check_something_function(x, y):
            # Code
    

    However, the class decorator solution is more practical.

提交回复
热议问题