【发布时间】:2019-08-14 12:21:24
【问题描述】:
我有一个包含firefox , atom , gnome-shell的任务列表文件
我的代码
import psutil
with open('tasklist', 'r') as task:
x = task.read()
print (x)
print ([p.info for p in psutil.process_iter(attrs=['pid', 'name']) if x in p.info['name']])
想要的
[{'pid': 413, 'name': 'firefox'}]
[{'pid': 8416, 'name': 'atom'}]
[{'pid': 2322, 'name': 'gnome-shell'}]
【问题讨论】:
-
实际的输出是?