#๐ variables inside lambda
35 messages ยท Page 1 of 1 (latest)
@echo stone
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
You can't unless you use the global keyword to define the variable.
well ur defining Cwindow inside a lambda's scope
In this case, the variable is local and only accessible inside the function.
yes ikr
how do i use global inside lamda
So imo just use a regular function instead of a lambda
you cannot
Although not recommended, you can use the global keyword to summon the variable. I don't know if it will work.
Oh yeah.
nonlocal is better.
Lambda expressions only allows you 1 line of code.
global requires your shared variable to be in the global (module) scope.
In this case, I'd rather recommend defining the variable before everything.
maybe a regular function
Just define the variable before everything.
W
You could make Cwindow an attribute of some shared object. You can set the attribute.
I don't think lambdas can alter variables in the global scope..
NOO
i didnt knew nonlocal was a thing
Okay gotta have dinner
It is not used very often
It's recentish.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.