python学习-sys模块
来源:互联网 发布:php 命名空间的用法 编辑:程序博客网 时间:2024/05/16 19:39
只写比较常用的,sys模块的其他DATA请参考help(sys).
1.sys.argv
shell脚本通过$x(x为数字)获取被送入脚本的参数,而python通过sys.argv做这一点,代码如下:
#!/usr/bin/env python#*-*coding:UTF-8 *-*import sysif __name__=='__main__': print sys.argv
测试:
john@john-pad:~/python_workspace/core$ python sys_demo.py var1 var2['sys_demo.py', 'var1', 'var2']
argv是一个列表,第一项即argv[0]是脚本的名称,并依次存储送进来的参数。
2.sys.exit()
该函数用以退出python解释器,接受一个参数,以下为该函数的doc string:
Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is numeric, it will be used as the system exit status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).
3.sys.path
是一个包含了字符串的列表,当需要加载某个module(模块)时就从这个列表中的字符串所代表的系统路径进行查找,可以试着打印一下该字段。
因为这是一个列表(list),所以可以通过列表的操作添加或者修改module的搜索路径,比如,我自己新写了一个module,需要将该module所在的目录添加到sys.path列表中
4.sys.modules
是一个包含了已被加载模块的列表,
5.sys.stdin sys.stdout sys.stderr
分别对应标准输入流 标准输出流 标准错误流
- python学习-sys模块
- Python模块学习:sys模块
- Python模块学习之sys
- PYTHON模块之sys
- python sys模块
- python sys模块详解!
- python sys模块详解
- python - sys模块
- Python sys 模块
- python中的Sys模块
- python的sys模块
- python sys.modules模块
- python sys模块
- python sys模块
- python - sys模块
- python Sys模块
- Python sys模块
- Python sys模块简介
- [leet code] Spiral Matrix II
- winsock和winsock2冲突
- C/C++简单的复制文件
- Chrome不支持showModalDialog模态对话框和无法返回returnValue的问题
- 插入排序的顺序表实现
- python学习-sys模块
- final exam
- MSSQL2008 数据库展开报错:值不能为空。 参数名: viewInfo (Microsoft.SqlServer.Management.SqlStudio.Expl
- 服务,活动均可以使用的sharePreference
- 关于redis使用set时设置超时时间的问题
- spring 提交流程
- Mysql InnoDB行锁实现方式
- 匹配文本中的网址java正则表达式
- Git常用操作命令收集