Namespaces 命名空间是命名到对象的映射.目前大多数命名空间是用Python的字典(dict)实现的,但是具体如何实现无关紧要,除非出于性能的考虑,并且将来可能改变其实现方式.例如命名空间是:built-in(builtins模块)的命名的集合,包括例如abs()函数或者built-in异常命名;函数调用的本地命名.在某种意义上对象的属性集也是一个命名
Namespaces are created at different moments and have different lifetimes. The namespace containing the 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; normally, module name...
Scopes and name resolution Do you remember when we talked about scopes and namespaces in Chapter 1, A Gentle Introduction to Python? We're going to expand on that concept now. Finally, we can talk about functions and this will make everything easier to understand. Let's start with a very...
For more information on the concepts covered in this course, check out: Namespaces and Scope in Python Python Scope & the LEGB Rule: Resolving Names in Your Code Exploring Scopes and Closures in Python Python Inner Functions: What Are They Good For? Python 3’s f-Strings: An Improved Strin...