12-1. Path search and search path. What is the difference between a path search and a search path?
The former refers to the operation of finding a file, which is to find a set of directories.
12-2.
Import properties. Suppose you have a Foo () function in your module mymodule.
(a) What are the two methods of importing this function into your namespace?
(b) What is the difference between the two methods of importing namespaces?
Import MyModule from Import foo
The first is to import all the attributes in MyModule, and the second imports only Foo
12-3. What is the difference between importing "import module" and "From Module import*"?
* is directly imported into the local namespace, so it can be used directly, without the need to add the module name qualification. You can import a standalone item or use the FROM module import * to import everything.
12-4. Namespaces and variable scopes. What is the difference between namespaces and variable scopes?
A namespace (namespaces) is a mapping of names (identifiers) to objects. The namespaces are divided into local namespaces (local namespaces), Global Namespaces (Globals Namespaces), and built-in namespaces (Build-in namespaces).
Build-in namespaces is first loaded into the active namespaces by the Python interpreter, which is made up of the names in the __buildins__ module.
Global namespaces is then loaded as an active namespaces, and you can use the Globals () built-in function to determine whether a name belongs to the global namespace.
Local namespaces when needed, that is, if a function is called during execution, it is loaded as an active namespaces, and you can use the locals () built-in function to determine whether a name belongs to a local namespace.
The scope of a variable (identifier) is defined as the scope of its declaration within the program (scope). See page 295 of this book. Variables defined within a function have a local scope, whereas variables of the highest level in a module have global scope.
Note that the names of all local spaces are within the local scope. All names outside the local scope are within the global scope.
Local namespaces and scopes change with function calls, and the global namespace does not change.
The following figure is from the original book. Added a Chinese comment, and some modifications. For reference only.
#本文来自博客园balian
Python Core Programming second Edition 12th after class answer