why do I get a keyerror | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
27th Jun 2020, 6:39 PM
Oma Falk
Oma Falk - avatar
8 Respostas
+ 3
Oma Falk , I think better use globals() function. Look at the code šŸ± https://code.sololearn.com/cEPJQGHXMi9Q/?ref=app
27th Jun 2020, 7:08 PM
TheWhĀ”teCat šŸ‡§šŸ‡¬
TheWhĀ”teCat šŸ‡§šŸ‡¬ - avatar
+ 4
Jannik MĆ¼ller thanks yes it helped. I stood on the pipeline. Noch vƶllig berauscht vom WerderduselšŸ’Ŗ
27th Jun 2020, 7:25 PM
Oma Falk
Oma Falk - avatar
+ 3
Oma Falk Ich schreibe es jetzt einfach mal auf Deutsch, weil es etwas schneller geht: Lokale Variablen sind Variablen, die wieder gelƶscht werden, wenn die Funktion, in der sie definiert wurden, durchgelaufen ist. Globale Variablen sind Variablen, die so lange wie der Prozess des Programms selbst erhalten bleiben. (AuƟer man lƶscht sie) Variablen, die auƟerhalb einer Funktion deklariert werden, sind standardmƤƟig global, und Variablen, die in einer Funktion deklariert werden, sind standardmƤƟig lokal. Wenn man eine globale Variable in einer Funktion deklarieren / weiterverwenden will, dann kann man das mit "global <Name>" machen. Ich hoffe, das hat geholfen. (Sorry to all the English speaking people, I had to write this one in German)
27th Jun 2020, 7:14 PM
Jannik MĆ¼ller
Jannik MĆ¼ller - avatar
+ 3
translation Oma Falk I just write it in German because it is a bit faster: Local variables are variables that are deleted again when the function in which they were defined has run through. Global variables are variables that remain as long as the process of the program itself. (Unless you delete them) Variables that are declared outside of a function are global by default, and variables that are declared in a function are local by default. If you want to declare / continue to use a global variable in a function, you can with "global <name>". I hope that helped. (Sorry to all the English speaking people, I had to write this one in German) Ā 
27th Jun 2020, 8:11 PM
Oma Falk
Oma Falk - avatar
27th Jun 2020, 7:09 PM
Oma Falk
Oma Falk - avatar
+ 2
haaaaaaarg locals are the locals of dict comprehension which creates a closurešŸ˜±šŸ˜±šŸ˜±
27th Jun 2020, 7:10 PM
Oma Falk
Oma Falk - avatar
+ 1
I think you have to replace locals() with globals(), because the variables were not declared in a function.
27th Jun 2020, 7:08 PM
Jannik MĆ¼ller
Jannik MĆ¼ller - avatar
+ 1
I want to understand one thing In below program, Can't we update globals() outside the comprehension? https://code.sololearn.com/c6Em4Yl1l59i/?ref=app Could you people help? basically I want to understand the trick inside below function, def func(args): [*map(globals().update, [{a: val(a)} for a in args.split()])]
27th Jun 2020, 8:20 PM
$Ā¢šŽā‚¹š”­!šØš“
$Ā¢šŽā‚¹š”­!šØš“ - avatar