When we import a module: Import xxx, by default the Python parser searches the current directory, installed built-in modules, and third-party modules, and the search path is stored in the path of the SYS module :
[Python]View PlainCopyprint?
- >>> Import sys
- >>> Sys.path
[‘‘,' C:\\python352\\lib\\idlelib ',' C:\\python352\\python35.zip ',' C:\\python352\\dlls ', ' C:\\python352\\lib ', ' c:\\python352 ', ' c:\\python352\\lib\\site-packages ', c:\\python352\\lib\\ Site-packages\\setuptools-28.6.1-py3.5.egg ', ' c:\\python352\\lib\\site-packages\\ Pip-8.1.2-py3.5.egg ', ' C:\\python352\\lib\\site-packages\\requests-2.11.1-py3.5.egg ' , ' C:\\python352\\lib\\site-packages\\xlutils-2.0.0-py3.5.egg ', ' C:\\python352\\lib\\site-packages\\xlwt-1.1.2-py3.5.egg ', \ C \python352\\lib\\site-packages\\pymongo-3.3.1-py3.5-win-amd64.egg ', ' C:\\Python352\\ Lib\\site-packages\\pytz-2016.7-py3.5.egg ', ' c:\\python352\\lib\\site-packages\\ Zope.interface-4.3.3-py3.5-win-amd64.egg ']
at this point, Sys.path returns a list! The path has been added to the environment variables of the system, and when we want to add our own search directory, we can use the Append () method of the list
1. For the module and its own script is not in the same directory, at the beginning of the script plus sys.path.append (' xxx '):
eg. Import SYS
Sys.path.append (' Address of the Reference module ')
2. Add the path to the environment variable of the system, or place the folder of that path within the path that has been added to the system environment variable. The contents of the environment variable are automatically added to the module search path.
P.s. The method and member properties can be viewed through DIR (SYS).
Reference article address: http://blog.csdn.net/jojoy_tester/article/details/54575264
About Sys.path.append ()