About Sys.path.append ()

Source: Internet
Author: User

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?
    1. >>> Import sys
    2. >>> 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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.