This is a self-made exercise and may be incorrect. You are welcome to discuss and discuss various optimization and reconstruction solutions.
12-1.
Path search and search path. What is the difference between path search and search path.
[Answer]
The Path Search refers to the operation to Search for a file (the pursuit of a file ), the latter is to find a group of directories (through a set of directories ). This article is from balian
The default search path is specified during compilation or installation. For more information about the current search path, see the following example. You can use the append () method of the List to add a search path.
>>> import sys>>> sys.path['', 'D:\\Python27\\python27.zip', 'D:\\Python27\\DLLs', 'D:\\Python27\\lib', 'D:\\Python27\\lib\\plat-win', 'D:\\Python27\\lib\\lib-tk', 'D:\\Python27', 'D:\\Python27\\lib\\site-packages']>>>
12-2.
Import attributes. Assume that your module mymodule contains a foo () function.
(A) How can I import this function to your namespace?
(B) What are the differences between the two imported namespaces?
[Answer]
(A) Use the import Statement (import module) and from-import Statement (from module import ). Avoid using the from module import * Statement.
(B) Using the from-import Statement, foo () is directly imported to a local namespace, so it must be used directly without the limitation of the module name.
If we use the path () function in the sys module of Question 12-1 as an example:
The code for using the first method (import module) is as follows:
>>> Import sys >>> sys. path # The limitation of the module name must be added: ['', 'd: \ Python27 \ python27.zip ', 'd: \ Python27 \ DLLs', 'd: \ Python27 \ lib ', 'd :\\ Python27 \ lib \ plat-win', 'd :\\ Python27 \ lib-tk ', 'd: \ python27', 'd: \ Python27 \ lib \ site-packages '] >>> path # note the error here, path () traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'path' is not defined >>>
The code for using the second method (from module import) is as follows:
>>> From sys import path >>> sys. path # main error here. The module name cannot be added with the Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'sys 'is not defined # This article is from the blog Park balian >>> path # path () must directly use ['', 'd: \ Python27 \ python27.zip ', 'd: \ Python27 \ DLLs ', 'd: \ Python27 \ lib', 'd: \ Python27 \ lib \ plat-win ', 'd: \ Python27 \ lib-tk ', 'd: \ Python27', 'd: \ Python27 \ lib \ site-packages '] >>>
[Reference]
Differences between the two import methods of the python Module
Http://developer.51cto.com/art/201003/189555.htm
Three methods for importing python modules
Http://www.docin.com/p-56218303.html
12-3.
What is the difference between importing "import module" and "from module import?
[Answer]
"From module import *" can import all the names of the specified module to the current namespace, but this usage must be limited. See the 317 page of this book.