Python 库与异常处理全解析
一、Python 库介绍
1.1 特定操作系统相关库
1.1.1 SGI IRIX 特定库
- 日志查看 :使用命令
tail -f /var/log/messages读取脚本写入日志的内容。 - popen2 模块 :允许通过运行外部命令创建进程,并使用管道连接其可访问的流(stdin、stdout 和 stderr)。示例代码如下:
import os,popen2
str1 = os.popen('ls','r').read()
print str1
out1,in1 = popen2.popen2('cat')
in1.write(str1)
in1.close()
str2 = out1.read()
out1.close()
print str2
从 Python 2.0 版本开始, popen2 、 popen3 、 popen4 函数在 Windows 平台也受支持。
- commands 模块 :通过为 os.popen() 函数实现包装函数,提供在 UNIX 下执行外部命令的功能。这些函数将系统命令作为字符串参数,并返回该命令生成的任何输出。
- 其他特定模块
超级会员免费看
订阅专栏 解锁全文
142

被折叠的 条评论
为什么被折叠?



