这种方式比直接在shell里面写awk之类的要友好很多,毕竟到了python里面处理就容易了。
内容 1 函数os的这个函数很有意思,可以认为通过os.popen执行后会产生了一个类似文本文件的内容。
import os
# 执行shell命令,返回文本段
def popen(some_cmd):
with os.popen(some_cmd) as f:
res = f.read()
这种方式比直接在shell里面写awk之类的要友好很多,毕竟到了python里面处理就容易了。
内容 1 函数os的这个函数很有意思,可以认为通过os.popen执行后会产生了一个类似文本文件的内容。
import os
# 执行shell命令,返回文本段
def popen(some_cmd):
with os.popen(some_cmd) as f:
res = f.read()