W
W
wenzeslaus2021-06-05 16:26:49
Python
wenzeslaus, 2021-06-05 16:26:49

How to display the process name correctly?

I want to display only process names. Initially the code looks like this

import psutil
for proc in psutil.process_iter(['name']):
    print(proc.info)

I decided to put it all in the list, so that after that I would send the list of processes in one message. But I only get the name parameter, not the process name itself. How to write down correctly so that the list displays exactly the name of the process?
import psutil
for proc in psutil.process_iter(["name"]):
    name = list(proc.info)
    print(f"{name[0]}")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy _, 2021-06-05
@wenzeslaus

import psutil
for proc in psutil.process_iter(['name']):
    print(proc.info['name'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question