【发布时间】:2019-08-27 09:38:48
【问题描述】:
@app.callback(
dash.dependencies.Output('output-container-button', 'children'),
[dash.dependencies.Input('button', 'n_clicks')],
[dash.dependencies.State('input-box', 'value')])
def update_output(n_clicks, value):
return 'The input value was "{}" and the button has been clicked {} times'.format(
value,
n_clicks
)
我发现这被称为“装饰器”,根据this answer,最常见的是@property、@classmethod 和@staticmethod。
这个例子不是这些。 app 是一个已经存在的对象。那么,从语法上讲(我正在寻找 Python 答案,而不是 Dash 答案),@object.method 是做什么的?
【问题讨论】:
-
和其他装饰器一模一样?
@one.two.three.whatever也可以,变化不大。 -
A decorator 只是一个返回另一个函数的函数(或可调用函数)。定义此类函数的方式或位置没有区别。
标签: python decorator python-decorators