Concepts
Aliasing
- Aliasing refers to objects that have multiple names
- When working with mutable objects (list, dictionary, and class), surprising effects may occur
- e.g. when passing the names of mutable objects into a function, it may be passed by value or passed by reference
Namespace
Namespace
- A Namespace is a systematic mapping of names to objects
- most namespace are currently implemented as dictionaries
- Examples of Namespaces:
- built-in names
- the global names in a module
- the local names in a function invocation
- the set of attributes of an objects
- Names in different namespaces are not related
Attribute
- An Attribute is any name following a dot
- Attributes may be read-only or writable
- For writable attribute, assignment is possible
- Writable attributes may also be deleted with the
del
statement
Namespace Lifetime
Namespace are created and destroyed
- The Namespace for built-in names is created when the Python interpreter starts up, and is never deleted
- The Global Namespace for a module is created when the module definition is read in and normally last until the interpreter quits
- The Local Namespace for a function is created when the function is called, and deleted when the function returns or raises an exception that is not handled within the function
Scope
- A Scope is the text region of code where a namespace can be accessed