【发布时间】:2020-02-29 15:24:17
【问题描述】:
我在网上检查了一些关于如何跟踪特定管道步骤的代码,我得到了以下代码:
class Pipeline():
def __init__(self, step_id, fct_to_call):
self.step_id = step_id
self.fct_to_call = fct_to_call
def __call__(self, *args):
return self.fct_to_call(*args)
def pipeline_step(step_id):
return lambda f: Pipeline(step_id=step_id, fct_to_call=f)
@pipeline_step(step_id='lacocouracha')
def my_sum(numba):
output = numba *1.45
return output
a = my_sum(12)
我的问题与我们何时使用 lambda 函数有关。当我在调试器模式下运行时,我看到 lambda 函数“f”指的是“my_sum”。那么当在装饰函数中使用 lambda 函数时,它会自动理解它是它想要作为输入的装饰函数吗?
非常感谢!
【问题讨论】:
标签: python oop lambda decorator