+ 1
What is namespace
4 ответов
+ 8
You can think of a namespace as a dictionary in which the keys are the object names and the values are the objects themselves.
+ 7
A way to separate variables to avoid name clashes.
+ 6
For example in Python, how you reach your variables varies with where they are. Consult the LEGB-modell:
L: Local variables are inside a function. You can’t reach them from outside the function.
E: Enclosing variables are variables you are trying to reach in an function from an nested function to that function you are trying to reach. To read it is always okey, but if you want to change it, you have to first declare it with nonlocal.
G: Global variables are variables in the modul layer. You can read them from inside a function, but if you want to change them, you have to first declare them as global.
B: Bult-in variables are variables in the built-in layer. If you for example assign len = 2 in the modul layer, you have to delete it first if you want to use the function len([1, 2, 3]), because your assignment otherwise will block the function in the built-in layer.
So from L you reach variables in LEGB, from E in EGB, and from G in GB. Hope this gives you a hint about namespsces.
/Regards Per B
+ 4
Thanks!