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. Sparse autoencoder implementation 稀疏自编码器实现

    任务:在这个问题中,你将实现稀疏自编码器算法,并且展示它怎么发现边缘是自然图像的一个好的表示. 在文件 sparseae_exercise.zip中,我们已经提供了一些Matlab中的初始代码,你应该 ...

  2. UDP发送的数据 以数据包形式发送

    UDP发送的数据 以数据包形式发送

  3. HTML表单之input元素的23种type类型

    摘自:http://www.cnblogs.com/xiaohuochai/p/5179909.html 了解HTML表单之input元素的23种type类型 随着HTML5的出现,input元素新增 ...

  4. [洛谷P4721]【模板】分治 FFT

    题目大意:给定长度为$n-1$的数组$g_{[1,n)}$,求$f_{[0,n)}$,要求: $$f_i=\sum_{j=1}^if_{i-j}g_j\\f_0=1$$ 题解:直接求复杂度是$O(n^ ...

  5. [洛谷P5057][CQOI2006]简单题

    题目大意:有一个长度为$n$的$01$串,两个操作: $1\;l\;r:$把区间$[l,r]$翻转($0->1,1->0$) $2\;p:$求第$p$位是什么 题解:维护前缀异或和,树状数 ...

  6. 玩(lay) 解题报告

    玩(lay) 题目名称 你的昆特牌打的太好啦!不一会你就 \(\tt{AK}\) 了 \(\tt{NOGP}\),只能无聊地堆牌玩! 题目描述 你有一些矩形卡牌,每次你会作如下三个操作: 紧挨着最后一 ...

  7. 项目管理---git----快速使用git笔记(三)------coding.net注册和新建项目(远程仓库)

    我们在第一章已经了解了github和coding.net的区别: github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要公开. codin ...

  8. hdu 5625

    Clarke and chemistry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  9. DOM通过ID或NAME获取值

    DOM通过ID或NAME获取值 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> &l ...

  10. java 课后作业

    杨辉三角 组合数 public class YH { public static void main(String agrs[]) { int a[5][5],i,j; for(i = 0;i < ...