0
import psutil
applist = list(psutil.process_iter())
for app in applist:
    print(app)

It's a script to get running Process in macOS, I got the list and it showed

psutil.Process(pid=12723, name='Google Chrome', status='running', started='13:54:23')

But I only want to get the 'Google Chrome' part, how can I do that? I want to use split(), but it said 'Process' object has no attribute 'split'.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

1

You can do

import psutil
applist = list(psutil.process_iter())
for app in applist:
    print(app.name())

If you want to know more read relevant psutil.Process docs piece.

Daweo
  • 31,313
  • 3
  • 12
  • 25