Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
函数变量的Python修饰符_Python_Python Decorators - Fatal编程技术网

函数变量的Python修饰符

函数变量的Python修饰符,python,python-decorators,Python,Python Decorators,在Python中,有没有一种方法可以将不同的装饰器作为变量分配给函数 例如(显然,以下代码不会执行): 提前谢谢 a_function_with_status_display = status_display(a_function) a_function_with_call_counter = call_counter(a_function) 你似乎能写装饰师,但你不知道他们做什么 你似乎能写装饰师,但你不知道他们做什么?太快了:)为什么我没想到?我现在就试试。我得看看它是否也适用于具有非空参

在Python中,有没有一种方法可以将不同的装饰器作为变量分配给函数

例如(显然,以下代码不会执行):

提前谢谢

a_function_with_status_display = status_display(a_function)
a_function_with_call_counter = call_counter(a_function)
你似乎能写装饰师,但你不知道他们做什么


你似乎能写装饰师,但你不知道他们做什么?

太快了:)为什么我没想到?我现在就试试。我得看看它是否也适用于具有非空参数列表的装饰器,但话说回来,为什么不呢?谢谢我从周三开始学习Python。我刚刚意识到@thing只是一个函数包装器的语法糖,而不是其他。确切地说,它只是语法糖。这很快:)为什么我没有想到这一点?我现在就试试。我得看看它是否也适用于具有非空参数列表的装饰器,但话说回来,为什么不呢?谢谢我从周三开始学习Python。我刚刚意识到@thing只是函数包装器的一个语法糖,而不是其他。确切地说,它只是一个语法糖。如果您还没有读过它,我建议您阅读这篇文章。
a_function()
加上括号意味着您实际上正在调用函数,这可能不是您想要的。(除非
a_函数
在调用时创建函数…)@flornqueke I will。我必须先学会思考,然后再学会修补,因为对我来说,这通常是另一种方式。再说一次,如果你想得太多,不修补,你就根本学不到东西。我想这都是关于平衡的,但是如果你这样想的话,顺序真的不重要。如果你还没有读过,我建议你读一下这个。
a_function()
加上括号意味着你实际上正在调用这个函数,这可能不是你想要的。(除非
a_函数
在调用时创建函数…)@flornqueke I will。我必须先学会思考,然后再学会修补,因为对我来说,这通常是另一种方式。再说一次,如果你想得太多,不修补,你就根本学不到东西。我想这一切都是为了平衡,但如果你这样想的话——顺序真的不重要。
a_function_with_status_display = status_display(a_function)
a_function_with_call_counter = call_counter(a_function)