1. 程式人生 > >python的sys模組介紹

python的sys模組介紹

sys有幾個python的內部函式和屬性,sys在這裡是指Python系統

1,sys.path 匯入模組時,python要查詢的目錄路徑的列表

2,sys.modules 當前已裝入模組的字典

3,sys.platform 當前平臺的名字字串

4, sys.argv 是命令列輸入的單詞列表,如果輸入包括python這個命令,sys.argv不會包括python本身的引用

5,sys.stdin 標準輸入流

6,sys.stdout 標準輸出流

7,sys.stderr 標準錯誤

測試程式碼:

import  sys
print sys.modules
print sys.path
print 
sys.platform print sys.argv

結果:

{'copy_reg': <module 'copy_reg' from 'D:\Python27\lib\copy_reg.pyc'>, 'sre_compile': <module 'sre_compile' from 'D:\Python27\lib\sre_compile.pyc'>, 'locale': <module 'locale' from 'D:\Python27\lib\locale.pyc'>, '_sre': <module '_sre' (built-in)>, 'functools': <module 'functools' from 'D:\Python27\lib\functools.pyc'>, 'encodings': <module 'encodings' from 'D:\Python27\lib\encodings\__init__.pyc'>, 'site': <module 'site' from 'D:\Python27\lib\site.pyc'>, '__builtin__': <module '__builtin__' (built-in)>, 'sysconfig': <module 'sysconfig' from 'D:\Python27\lib\sysconfig.pyc'>, 'operator': <module 'operator' (built-in)>, '__main__': <module '__main__' from 'C:/Users/XuQiaoBo/PycharmProjects/test/Main.py'>, 'types': <module 'types' from 'D:\Python27\lib\types.pyc'>, 'encodings.encodings': None, 'encodings.gbk': <module 'encodings.gbk' from 'D:\Python27\lib\encodings\gbk.pyc'>, 'abc': <module 'abc' from 'D:\Python27\lib\abc.pyc'>, '_weakrefset': <module '_weakrefset' from 'D:\Python27\lib\_weakrefset.pyc'>, 'encodings._codecs_cn': None, 'errno': <module 'errno' (built-in)>, 'encodings.codecs': None, 'sre_constants': <module 'sre_constants' from 'D:\Python27\lib\sre_constants.pyc'>, 're': <module 're' from 'D:\Python27\lib\re.pyc'>, '_abcoll': <module '_abcoll' from 'D:\Python27\lib\_abcoll.pyc'>, 'ntpath': <module 'ntpath' from 'D:\Python27\lib\ntpath.pyc'>, '_codecs': <module '_codecs' (built-in)>, 'encodings._multibytecodec': None, 'nt': <module 'nt' (built-in)>, '_warnings': <module '_warnings' (built-in)>, 'genericpath': <module 'genericpath' from 'D:\Python27\lib\genericpath.pyc'>, 'stat': <module 'stat' from 'D:\Python27\lib\stat.pyc'>, 'zipimport': <module 'zipimport' (built-in)>, 'encodings.__builtin__': None, 'warnings': <module 'warnings' from 'D:\Python27\lib\warnings.pyc'>, 'UserDict': <module 'UserDict' from 'D:\Python27\lib\UserDict.pyc'>, '_multibytecodec': <module '_multibytecodec' (built-in)>, 'sys': <module 'sys' (built-in)>, 'codecs': <module 'codecs' from 'D:\Python27\lib\codecs.pyc'>, 'os.path': <module 'ntpath' from 'D:\Python27\lib\ntpath.pyc'>, '_functools': <module '_functools' (built-in)>, '_codecs_cn': <module '_codecs_cn' (built-in)>, '_locale': <module '_locale' (built-in)>, 'signal': <module 'signal' (built-in)>, 'traceback': <module 'traceback' from 'D:\Python27\lib\traceback.pyc'>, 'linecache': <module 'linecache' from 'D:\Python27\lib\linecache.pyc'>, 'encodings.aliases': <module 'encodings.aliases' from 'D:\Python27\lib\encodings\aliases.pyc'>, 'exceptions': <module 'exceptions' (built-in)>, 'sre_parse': <module 'sre_parse' from 'D:\Python27\lib\sre_parse.pyc'>, 'os': <module 'os' from 'D:\Python27\lib\os.pyc'>, '_weakref': <module '_weakref' (built-in)>}


['C:\\Users\\XuQiaoBo\\PycharmProjects\\test', 'C:\\Users\\XuQiaoBo\\PycharmProjects\\test', 'C:\\Windows\\SYSTEM32\\python27.zip', 'D:\\Python27\\DLLs', 'D:\\Python27\\lib', 'D:\\Python27\\lib\\plat-win', 'D:\\Python27\\lib\\lib-tk', 'D:\\Python27', 'D:\\Python27\\lib\\site-packages']


win32


['C:/Users/XuQiaoBo/PycharmProjects/test/Main.py']