Namespace
A mapping from name to objects. Names in different namespaces have no relation at all. Most namespaces are currently implemented as Python dictionaries e.g.: the set of built-in names; global names in a module; local names in a function invocation; in a sense, the attributes of an objectNamespaces are created at different moments and have different lifetimes.
Attribute
Any name following a dot. modules’s attribute vs. global names in the module : they are not the same, but they share the same namespace. exception is __dict__ attribute is not a global name in that module.Attibutes may be read-only or writable. Writable attibutes can be assigned value or be delted by “del” keyword.
Scope
A scope is a textual region of the Python program when a namespace is directly accessible. i.e.: don’t need dot. At least three nested scopes whose namespaces are ditrectly accessible:- the innter most scope( the namespaces of any enclosing function);
- middle scope: current module’s global names
- outermost scope: the namespace containing built-in names.
**[博主按]: And there is a scope that can be imported from module. When there’s confliction between names imorted from scope, the reference will go to the last imported one.
最新评论