1.sys.argv 可以实现从程序外部向程序传递参数
2.sys.exit() 程序中间退出,exit(0)正常退出,其他为异常退出
3.sys.getdefaultencoding() 获取系统编码方式
4.sys.setdefaultencoding() 设置系统编码方式
5.sys.getfilesystemencoding() 获取文件系统编码方式
6.sys.path 获取系统环境变量中PATH的路径字符串
7.sys.path.append("路径") 追加路径到系统环境变量PATH的后面
8.sys.path.insert("路径") 将路径插入到系统环境变量PATH的最前面
9.sys.platform: 获取当前系统平台。
10.sys.modules 是一个全局字典,该字典是python启动后就加载在内存中。每当程序员导入新的模块,sys.modules将自动记录该模块。当第二次再导入该模块时,python会直接到字典中查找,从而加快了程序运行的速度。它拥有字典所拥有的一切方法。

1
2
3
print(sys.modules.keys())
print(sys.modules.values())
print(sys.modules["os"])

输出结果:

1
2
3
dict_keys(['sys', 'builtins', '_frozen_importlib', '_imp', '_thread', '_warnings', '_weakref', 'zipimport', '_frozen_importlib_external', '_io', 'marshal', 'nt', 'winreg', 'encodings', 'codecs', '_codecs', 'encodings.aliases', 'encodings.utf_8', '_signal', '__main__', 'encodings.latin_1', 'io', 'abc', '_abc', 'site', 'os', 'stat', '_stat', 'ntpath', 'genericpath', 'os.path', '_collections_abc', '_sitebuiltins', '_bootlocale', '_locale', 'encodings.gbk', '_codecs_cn', '_multibytecodec', 'encodings.cp437', 'sitecustomize'])
dict_values([<module 'sys' (built-in)>, <module 'builtins' (built-in)>, <module '_frozen_importlib' (frozen)>, <module '_imp' (built-in)>, <module '_thread' (built-in)>, <module '_warnings' (built-in)>, <module '_weakref' (built-in)>, <module 'zipimport' (built-in)>, <module '_frozen_importlib_external' (frozen)>, <module 'io' (built-in)>, <module 'marshal' (built-in)>, <module 'nt' (built-in)>, <module 'winreg' (built-in)>, <module 'encodings' from 'D:\\Programs\\Python\\Python37\\lib\\encodings\\__init__.py'>, <module 'codecs' from 'D:\\Programs\\Python\\Python37\\lib\\codecs.py'>, <module '_codecs' (built-in)>, <module 'encodings.aliases' from 'D:\\Programs\\Python\\Python37\\lib\\encodings\\aliases.py'>, <module 'encodings.utf_8' from 'D:\\Programs\\Python\\Python37\\lib\\encodings\\utf_8.py'>, <module '_signal' (built-in)>, <module '__main__' from 'D:/Programs/Python/PycharmProjects/OldManS14/day05/module/sys_模块.py'>, <module 'encodings.latin_1' from 'D:\\Programs\\Python\\Python37\\lib\\encodings\\latin_1.py'>, <module 'io' from 'D:\\Programs\\Python\\Python37\\lib\\io.py'>, <module 'abc' from 'D:\\Programs\\Python\\Python37\\lib\\abc.py'>, <module '_abc' (built-in)>, <module 'site' from 'D:\\Programs\\Python\\Python37\\lib\\site.py'>, <module 'os' from 'D:\\Programs\\Python\\Python37\\lib\\os.py'>, <module 'stat' from 'D:\\Programs\\Python\\Python37\\lib\\stat.py'>, <module '_stat' (built-in)>, <module 'ntpath' from 'D:\\Programs\\Python\\Python37\\lib\\ntpath.py'>, <module 'genericpath' from 'D:\\Programs\\Python\\Python37\\lib\\genericpath.py'>, <module 'ntpath' from 'D:\\Programs\\Python\\Python37\\lib\\ntpath.py'>, <module '_collections_abc' from 'D:\\Programs\\Python\\Python37\\lib\\_collections_abc.py'>, <module '_sitebuiltins' from 'D:\\Programs\\Python\\Python37\\lib\\_sitebuiltins.py'>, <module '_bootlocale' from 'D:\\Programs\\Python\\Python37\\lib\\_bootlocale.py'>, <module '_locale' (built-in)>, <module 'encodings.gbk' from 'D:\\Programs\\Python\\Python37\\lib\\encodings\\gbk.py'>, <module '_codecs_cn' (built-in)>, <module '_multibytecodec' (built-in)>, <module 'encodings.cp437' from 'D:\\Programs\\Python\\Python37\\lib\\encodings\\cp437.py'>, <module 'sitecustomize' from 'D:\\Programs\\Python\\PyCharm 2018.1.4\\helpers\\pycharm_matplotlib_backend\\sitecustomize.py'>])
<module 'os' from 'D:\\Programs\\Python\\Python37\\lib\\os.py'>

11. stdin , stdout , 以及stderr 变量包含与标准I/O 流对应的流对象. 如果需要更好地控制输出,,而print 不能满足你的要求, 它们就是你所需要的. 你也可以替换它们, 这时候你就可以重定向输出和输入到其它设备( device ), 或者以非标准的方式处理它们

1
2
3
sys.stderr.write("stderr")
print("=======")
sys.stdout.write("stdout")

输出结果:

1
2
stderr=======
stdout

Pythone3 sys模块的更多相关文章

  1. python常用模块(模块和包的解释,time模块,sys模块,random模块,os模块,json和pickle序列化模块)

    1.1模块 什么是模块: 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文 ...

  2. python标准模块(os及sys模块)

    一.os模块 用于提供系统级别的操作 os.getcwd() 获取当前工作目录 os.stat('path/filename') 获取文件/目录信息,其中包括文件大小等 os.sep 获得操作系统特定 ...

  3. [转载]python中的sys模块(二)

    #!/usr/bin/python # Filename: using_sys.py import sys print 'The command line arguments are:' for i ...

  4. [转载]Python中的sys模块

    #!/usr/bin/python # Filename: cat.py import sys def readfile(filename): '''Print a file to the stand ...

  5. python之sys模块详解

    python之sys模块详解 sys模块功能多,我们这里介绍一些比较实用的功能,相信你会喜欢的,和我一起走进python的模块吧! sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传 ...

  6. sys模块和os模块,利用sys模块生成进度条

    sys模块import sysprint(sys.argv)#sys.exit(0)             #退出程序,正常退出exit(0)print(sys.version)       #获取 ...

  7. os和sys模块

    sys模块 sys模块主要是用于提供对python解释器相关的操作 函数 sys.argv #命令行参数List,第一个元素是程序本身路径 sys.path #返回模块的搜索路径,初始化时使用PYTH ...

  8. python中os和sys模块的详解

    平时在工作中经常会用到os模块和sys模块的一些特性,下面是这些特性的一些相关解释,希望对大家有所帮助 os模块 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os. ...

  9. Python学习总结12:sys模块

    sys模块常用来处理Python运行时配置以及资源,从而可以与前当程序之外的系统环境交互. 1. 导入及函数查看 >>> import sys #导入sys模块 >>&g ...

随机推荐

  1. VS升级后的配置问题

    当vs升级到更新的版本后,运行原来无误的程序会出现一系列问题. 例如:打不开iostream文件,lib文件,系统找不到文件等等 出现这类问题的原因是,编译环境的include path和librar ...

  2. WPF布局间的切换方法

    效果图,两种效果间的切换

  3. BZOJ4000 TJOI2015棋盘(状压dp+矩阵快速幂)

    显然每一行棋子的某种放法是否合法只与上一行有关,状压起来即可.然后n稍微有点大,矩阵快速幂即可. #include<iostream> #include<cstdio> #in ...

  4. ADC关键性能指标及误区

    ADC关键性能指标及误区 由于ADC产品相对于网络产品和服务器需求小很多,用户和集成商在选择产品时对关键指标的理解难免有一些误区,加之部分主流厂商刻意引导,招标规范往往有不少非关键指标作被作为必须符合 ...

  5. 【题解】Atcoder AGC#03 E-Sequential operations on Sequence

    仙题膜拜系列...首先我们可以发现:如果在截取了一段大的区间之后再截取一段小的区间,显然是没有什么用的.所以我们可以将操作序列变成单调递增的序列. 然后怎么考虑呢?启示:不一定要考虑每一个数字出现的次 ...

  6. 【BZOJ1941】Hide and Seek(KD-Tree)

    [BZOJ1941]Hide and Seek(KD-Tree) 题面 BZOJ 洛谷 题解 \(KD-Tree\)对于每个点搜一下最近点和最远点就好了 #include<iostream> ...

  7. AOJ.综合训练.2016-12-1

    友情提示:不要复制粘贴,看完解析先自己尝试写一下,不行再看代码!祝AC愉快 @_@ A. 近似值计算 题意分析 根据公式,先用含有n的代数式表示出来pi,然后计算这个近似值和题目给出来的3.14159 ...

  8. sourcemap总结

    sourcemap在线上压缩文件调试中很重要,在此总结如下: 1. 开启sourcemap (1). 浏览器要开启source-map支持(2). 压缩文件底部要有source-map的URL,压缩要 ...

  9. bzoj2144: 跳跳棋(二分/倍增)

    思维好题! 可以发现如果中间的点要跳到两边有两种情况,两边的点要跳到中间最多只有一种情况. 我们用一个节点表示一种状态,那么两边跳到中间的状态就是当前点的父亲,中间的点跳到两边的状态就是这个点的两个儿 ...

  10. HDU 5646

    DZY Loves Partition Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...