Need info about bind function. (multi arguments) #2188
-
Hi everyone, I would to use few argument with a bind function. It seem that the lambda why generate a bug in my test. for each in document.select('#TestDIV textarea'):
each.bind("input", lambda ev: TheFunction(ev, what=each.name , aVariable=1000)) The error here is that all the what variable have the same output in each loop :/ So instead of a lambda is there a more classical why ? I've tried few other but it always fail because I need to pass the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi ! This kind of issue (which is not specific to Brython) is solved by passing the loop variable to the lambda function: from browser import document
def f(ev, what):
print(what)
for each in document.select('div'):
each.bind("click", lambda ev, each=each: f(ev, what=each.name)) |
Beta Was this translation helpful? Give feedback.
-
In this case, |
Beta Was this translation helpful? Give feedback.
Hi !
This kind of issue (which is not specific to Brython) is solved by passing the loop variable to the lambda function: