I have a fairly easy Python3 script, which also uses Dash:
app = dash.Dash(__name__)
app.layout = html.Div(id='mydiv', ...)
fff = False
@app.callback(
Output('mydiv', '...'),
Input('mydiv', 'myevent')
def update(evt):
print(fff)
return dash.no_update
This correctly prints 'False' when the update
function is called on click on the div.
However, a slight modification makes python not interpret my whole file:
app = dash.Dash(__name__)
app.layout = html.Div(id='mydiv', ...)
fff = False
@app.callback(
Output('mydiv', '...'),
Input('mydiv', 'myevent')
def update(evt):
*** print(fff)
fff = True
return dash.no_update
This makes "Unresolved reference 'fff'" in line marked with ***
If I put "nonlocal fff" in front of that unresolved reference line, there is a syntax error of
SyntaxError: no binding for nonlocal 'fff' found
Why is this happening? Why can the python print fff's value if I don't want to modify it?
And how can I modify it in this update
function?