Import module python
When we import a module: import xxx, by default python parser will search the current directory, installed built-in modules and third-party module search path stored in the path sys module in:
- >>> 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 system environment variables when we want to add your own search directory, you can append through the list () method
1. For the script to write their own modules and is not under the same directory, in the beginning of the script plus sys.path.append ( 'xxx'):
eg. import sys
sys.path.append ( 'module address referenced')
The relative introduced:
sys.path.append(..)
2. Add the path environment variable to the system, or the path of the file into the folder in the system environment variables have been added to the path. The contents of environment variables are automatically added to the module search path.
ps can view the inside of his methods and member properties by dir (sys).
https://www.cnblogs.com/mandy-study/p/7735801.html