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. opencv2.4.0版本不支持Mat的大小自动调整?

    在opencv2.4.9中,resize(img,img,Size(850,550))是没问题的.到了2.4.0中,要新声明一个变量Mat img1;resize(img,img1,Size(850, ...

  2. Spring Boot中使用@Transactional注解配置事务管理

    事务管理是应用系统开发中必不可少的一部分.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的两种方式.编程式事务指的是通过编码方式实现事务:声明式事务基于 AOP ...

  3. 【Linux】linux中删除指定文件外所有其他文件(夹)的问题

    今天碰到要删除指定文件(夹)外的其他文件的问题.网上查到的方法是这样的 需要在当前文件夹中进行: rm -rf !(keep) #删除keep文件之外的所有文件 rm -rf !(keep1|keep ...

  4. Shell中sort-cut-wc详解

    sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 ...

  5. MATLAB中imfilter函数

    功能:对任意类型数组或多维图像进行滤波. 用法:B = imfilter(A,H) B = imfilter(A,H,option1,option2,...) 或写作g = imfilter(f, w ...

  6. iOS-学习UIKIt框架的重要性

      前言: 众所周知,我们的移动设备的屏幕上可以展示很多图形界面,作为用户的我们可以通过屏幕上的图形界面浏览信息,也可以通过与图形界面的简单交互,在移动设备上实现各种各样的功能操作.....可以说,没 ...

  7. CF961D Pair Of Lines

    题目描述 You are given n n n points on Cartesian plane. Every point is a lattice point (i. e. both of it ...

  8. CF527A:Playing with Paper——题解

    https://vjudge.net/problem/CodeForces-527A http://codeforces.com/problemset/problem/527/A 题目大意:一个纸长a ...

  9. 【bzoj2743】[HEOI2012]采花 树状数组

    题目描述 萧芸斓是Z国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了n朵花,花有c种颜色(用整数1-c表示),且花是排成一排的,以便于公 ...

  10. BZOJ1006 神奇的国度 【弦图染色——最大势算法MCS】

    1006: [HNOI2008]神奇的国度 Time Limit: 20 Sec  Memory Limit: 162 MB Submit: 4146  Solved: 1916 [Submit][S ...