小编ANV*_*ANV的帖子

如何使用 Python 从文本中提取一列?

我是python编程的新手。通过在互联网上搜索 python 文档来编写此脚本。

任何人都可以帮助我仅将第二列作为“ps aux”命令的输出(即仅 PID 列)。

#script to print the processid
import os
import commands
out=commands.getoutput('ps aux') # to get the process listing in out
#print out
#print out[2] #print only second column from out
print out[:2] 

output of "print out" statement
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   5728  1068 ?        Ss   Oct13   0:07 /sbin/init
root         2  0.0  0.0      0     0 ?        S<   Oct13   0:00 [kthreadd]
root         3  0.0  0.0 …
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
1
解决办法
8081
查看次数

标签 统计

python ×1