Pythone3 sys模块
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模块的更多相关文章
- python常用模块(模块和包的解释,time模块,sys模块,random模块,os模块,json和pickle序列化模块)
1.1模块 什么是模块: 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文 ...
- python标准模块(os及sys模块)
一.os模块 用于提供系统级别的操作 os.getcwd() 获取当前工作目录 os.stat('path/filename') 获取文件/目录信息,其中包括文件大小等 os.sep 获得操作系统特定 ...
- [转载]python中的sys模块(二)
#!/usr/bin/python # Filename: using_sys.py import sys print 'The command line arguments are:' for i ...
- [转载]Python中的sys模块
#!/usr/bin/python # Filename: cat.py import sys def readfile(filename): '''Print a file to the stand ...
- python之sys模块详解
python之sys模块详解 sys模块功能多,我们这里介绍一些比较实用的功能,相信你会喜欢的,和我一起走进python的模块吧! sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传 ...
- sys模块和os模块,利用sys模块生成进度条
sys模块import sysprint(sys.argv)#sys.exit(0) #退出程序,正常退出exit(0)print(sys.version) #获取 ...
- os和sys模块
sys模块 sys模块主要是用于提供对python解释器相关的操作 函数 sys.argv #命令行参数List,第一个元素是程序本身路径 sys.path #返回模块的搜索路径,初始化时使用PYTH ...
- python中os和sys模块的详解
平时在工作中经常会用到os模块和sys模块的一些特性,下面是这些特性的一些相关解释,希望对大家有所帮助 os模块 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os. ...
- Python学习总结12:sys模块
sys模块常用来处理Python运行时配置以及资源,从而可以与前当程序之外的系统环境交互. 1. 导入及函数查看 >>> import sys #导入sys模块 >>&g ...
随机推荐
- Visual C++中对运行时库的支持
原文地址:http://blog.csdn.net/wqvbjhc/article/details/6612099 一.什么是C运行时库 1)C运行时库就是 C run-time library,是 ...
- [C/C++] C++模板定义格式
函数模板的格式: template <class 形参名,class 形参名,......> 返回类型 函数名(参数列表) { //函数体 } 类模板的格式为: template<c ...
- 使用WebClient类对网页下载源码,对文件下载保存及异步下载并报告下载进度
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAx4AAAI7CAIAAADtTtpYAAAgAElEQVR4nO3dX6xlV33Y8f3UJFUqHq
- 【python】使用枚举类
当我们需要定义常量时,一个办法是用大写变量通过整数来定义,例如月份: JAN = 1 FEB = 2 MAR = 3 ... NOV = 11 DEC = 12 好处是简单,缺点是类型是int,并且仍 ...
- RT-thread内核之信号量
一.信号量控制块:在include/rtdef.h中 #ifdef RT_USING_SEMAPHORE /** * Semaphore structure */ struct rt_semaphor ...
- 【题解】Atcoder ARC#83 E-Bichrome Tree
哈哈~自己做出来的E题!(虽然这题被机房大佬强D极水).最开始神经错乱,写了个完全不对的贪心,竟然只错了4个点(。•ˇ‸ˇ•。) 可以发现,一个节点的子树内部和他颜色相同的节点权值和 是固定的,那么不 ...
- UVA.10130 SuperSale (DP 01背包)
UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...
- jquery 操作实例一
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- HTTP的消息结构?
参考:http://www.runoob.com/http/http-messages.html (1)请求数据包结构: 第一部分:请求行(数据包的第一行内容)[GET/HTTP/1.1] 请求行包含 ...
- Android线程池ThreadPoolExecutor
阿里巴巴Android开发手册[强制]新建线程时,必须通过线程池提供(AsyncTask 或者 ThreadPoolExecutor或者其他形式自定义的线程池),不允许在应用中自行显式创建线程说明:使 ...