使用python 的os.system执行系统命令
使用如下方法:
import os print os.system('ping www.savh.cn')
输出结果:
64 bytes from 104.27.148.191: icmp_seq=0 ttl=245 time=6.798 ms 64 bytes from 104.27.148.191: icmp_seq=1 ttl=244 time=7.561 ms 64 bytes from 104.27.148.191: icmp_seq=1 ttl=246 time=7.161 ms 64 bytes from 104.27.148.191: icmp_seq=1 ttl=245 time=5.123 ms 64 bytes from 104.27.148.191: icmp_seq=1 ttl=248 time=7.146 ms
大部分动作都是由os模块来帮助完成,pythonk中现成的模块功能非常多,这是python的特色
接下来再来做另外一个例子:
import os print os.system('ifconfig')
执行后可以取出网卡信息,大家也可以用python os.system 来尝试更多的系统命令,方便快捷。

http://www.savh.cn/thread-169.htm
转载请注明:Savh.Cn 发表