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 ..