python的sys模块介绍
2017-05-25 11:43
369 查看
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 标准错误
测试代码:
结果:
{'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']
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']
相关文章推荐
- Python基本模块介绍:sys、platform
- Python Import机制备忘-模块搜索路径(sys.path)、嵌套Import、package Import
- Python Import机制备忘-模块搜索路径(sys.path)、嵌套Import、package Import
- python urllib2模块介绍
- PYTHON模块之sys
- PYTHON模块介绍
- python内置模块[sys,os,os.path,stat]
- python fileinput模块介绍
- Python Import机制备忘-模块搜索路径(sys.path)、嵌套Import、package Import
- python re模块 sub方法介绍
- python sys模块
- Python之sys模块小探
- Python常用模块种类的系统介绍及与操作系统相关的调用和操作
- Python常用模块种类的系统介绍及与操作系统相关的调用和操作
- python模块介绍
- Python Import机制备忘-模块搜索路径(sys.path)、嵌套Import、package Import
- Python常用模块种类的系统介绍及与操作系统相关的调用和操作
- 介绍python的OS模块功能
- python urllib 模块介绍
- Python图像处理库:PIL中Image,ImageDraw等基本模块介绍