#๐Ÿ”’ variables inside lambda

35 messages ยท Page 1 of 1 (latest)

echo stone
#

How can i use var Cworld

cobalt idolBOT
#

@echo stone

Python help channel opened

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.

humble perch
simple kelp
#

well ur defining Cwindow inside a lambda's scope

humble perch
#

In this case, the variable is local and only accessible inside the function.

echo stone
simple kelp
simple kelp
humble perch
#

Although not recommended, you can use the global keyword to summon the variable. I don't know if it will work.

humble perch
ashen zealot
#

nonlocal is better.

humble perch
#

Lambda expressions only allows you 1 line of code.

ashen zealot
#

global requires your shared variable to be in the global (module) scope.

humble perch
#

In this case, I'd rather recommend defining the variable before everything.

ashen zealot
#

nonlocal will find it in any enclosing scope.

#

Can't use either in a lambda.

humble perch
#

@echo stone So... what will you pick?

#

Oh wait there's no choice

echo stone
#

maybe a regular function

humble perch
#

Just define the variable before everything.

simple kelp
#

W

ashen zealot
#

You could make Cwindow an attribute of some shared object. You can set the attribute.

simple kelp
humble perch
#

NOO

echo stone
#

i didnt knew nonlocal was a thing

humble perch
#

Okay gotta have dinner

humble perch
#

ok bye fr

simple kelp
ashen zealot
echo stone
#

oo makes sense

#

thanks guys

#

!close

cobalt idolBOT
#
Python help channel closed

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.