码迷,mamicode.com
首页 > 编程语言 > 详细

python与系统做交互常用的模块和使用方法

时间:2017-01-18 12:43:56      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:python   表示   pop   常用   popen   stat   tput   pen   output   

1.使用os模块与系统做简单命令的交互

>>>import os

>>>os.popen(‘pwd‘)

<open file ‘pwd‘, mode ‘r‘ at 0x7f6e27b6a420>

>>>a = os.popen(‘pwd‘).read()

>>>a

‘/root\n‘

 

2.使用commands模块

>>>import commands

>>>res = commands.getstatusoutput(‘pwd‘)

>>>res

(0, ‘/root‘)

0表示执行结果的状态,非零的话表示执行结果有错误。

python与系统做交互常用的模块和使用方法

标签:python   表示   pop   常用   popen   stat   tput   pen   output   

原文地址:http://www.cnblogs.com/i1991/p/6296175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!