Namespace and scopes in python
Namespaces A Namespace Python is a mapping between variable names and objects . There are 3 general kinds of namespaces , main, and builtins namespaces — All the erected in names live then and this namespace is created when the practitioner starts up. Global namespace — All names declared with the global keyword live then . Original namespace — The original variables declared within a module or a function belong then . Compass A Compass is a textual area of a Python program where a Namespace is directly accessible . Any direct reference to a name with in a compass is directly looked up in the namespace the compass has access to. Name hunt When a python law executes, a hunt for a name happens in this order . Original — Hunt for the name in the original namespace of the function Enclosing — If it’s not present in the original namespace, hunt for it in the compass of the enclosing function .