==commands 模块==
(只用于 Unix) ``commands`` 模块包含一些用于执行外部命令的函数.
[Example 3-7 #eg-3-7] 展示了这个模块.
====Example 3-7. 使用 commands 模块====[eg-3-7]
```
File: commands-example-1.py
import commands
stat, output = commands.getstatusoutput("ls -lR")
print "status", "=>", stat
print "output", "=>", len(output), "bytes"
*B*status => 0
output => 171046 bytes*b*
```
本文介绍了Python中commands模块的使用方法,通过示例代码展示了如何利用该模块在Unix系统中执行外部命令并获取状态及输出。这为需要在Python脚本中调用系统命令的开发者提供了实用的指导。
2157

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



