Python's enbedded functions - what rules do apply? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Python's enbedded functions - what rules do apply?

I am sometimes defining a function within a function definition. It seems to me that different rules apply: Whatever I do, I can't get reading access to the global names, unless I pass them as args, and I also can't cram stuff into global containers from floor -2, like I would from floor -1. What are the differences of this kind of embedded functions and the reasons behind them? And when does it make sense to use them in the first place?

24th Jul 2018, 10:09 AM
HonFu
HonFu - avatar
3 Answers
+ 1
I believe you need to find out what closures are.
25th Jul 2018, 12:13 PM
strawdog
strawdog - avatar
+ 1
Nice cue, thanks - I'll look into it!
25th Jul 2018, 1:27 PM
HonFu
HonFu - avatar
0
Finally I got it. ^^' Classes in the import file get imported completely; but names in the module file that start with a _ won't be imported.
26th Dec 2018, 6:17 PM
HonFu
HonFu - avatar