调用前的Python装饰函数 [英] Python decorating functions before call
本文介绍了调用前的Python装饰函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个别人写的相当复杂的装饰器。我想做的是一次基于决策的调用该函数的修饰版本,或者再次调用该原始函数(未修饰)。
I have a rather complex decorator written by someone else. What I want to do is call a decorated version of the function one time based on a descision or call the original function (not decorated) another time. Is this possible?
推荐答案
使用:
decorator(original_function)()
没有:
original_function()
一个装饰器只是一个将一个函数作为参数并返回另一个函数的函数。 @语法完全是可选的。也许通过一些文档的筛选可能会有助于弄清楚事情。
A decorator is just a function which takes a function as an argument and returns another one. The @ syntax is totally optional. Perhaps a sift through some documentation might help clarify things.
这篇关于调用前的Python装饰函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文