Example of using the python sys module sys. path

Source: Internet
Author: User

The python sys module contains functions related to the python interpreter and its environment. You can use dir (sys) to view the methods and member attributes in the interpreter.

Copy codeThe Code is as follows:
Import sys
Print dir (sys)

Result:

Copy codeThe Code is as follows:
['_ Displayhook _', '_ doc _', '_ thook _', '_ name __', '_ package _', '_ stderr _', '_ stdin _', '_ stdout _', '_ clear_type_cache ', '_ current_frames', '_ getframe', '_ mercurial', 'api _ version', 'argv', 'builtin _ module_names ', 'byteorder ', 'Call _ tracing', 'callstats', 'copyright', 'displayhook', 'dlhandle', 'dont _ write_bytecode', 'exc _ clear', 'exc _ info ', 'exc _ type', 'mongothook', 'exec _ prefix', 'executable', 'exit ', 'flags', 'float _ info', 'float _ repr_style ', 'getcheckinterval', 'getdefaultencoding ', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit ', 'getrefercount', 'getsize', 'gettrack', 'getwindowsversion', 'hexversion ', 'Long _ info', 'maxint', 'maxsize', 'maxunicode ', 'meta _ path', 'modules', 'path', 'path _ hooks ', 'path _ importer_cache ', 'Platform', 'prefix', 'py3kwarning', 'setcheckinterval ', 'setprofile', 'setrecursionlimit ', 'settrack', 'stderr ', 'stdin ', 'stdout', 'subversion', 'version', 'version _ info', 'warnoptions', 'winver ']

Copy codeThe Code is as follows:
Import sys
Print sys. path
Result:
['C: \ Documents and Settings \ username \ My Documents \ Aptana Studio 3 Workspace \ Python_Test_Project \ src ', 'c: \ Documents and Settings \ username \ My Documents \ Aptana Studio 3 Workspace \ Python_Test_Project \ src ', 'c: \ Python27', 'c: \ Python27 \ DLLs ', 'c: \ Python27 \ lib', 'c: \ Python27 \ lib-tk ', 'c: \ Python27 \ lib \ plat-win ', 'c: \ Python27 \ lib \ site-packages', 'c: \ Python27 \ lib \ site-packages \ wx-2.8-msw-unicode ', 'c: \ WINDOWS \ system32 \ python27.zip']

There is a sys. path attribute. He is a list. If python imports files or modules, he will first find the module path in sys. path. If no, the program reports an error.
Therefore, we generally write programs by ourselves. You 'd better add your module path to the scan path of the current module. For example: sys. path. append ('your module name'), so that the program will not
An error is reported because the module cannot be found ..

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.