import psutil
name = "notepad.exe"
for proc in psutil.process_iter():
if proc.name().lower() == name.lower():
print("found")
elif proc.name().lower() != name.lower():
print("not found")
output:
not found
not found
not found
found
not found
not found
"notepad.exe" was open from the start and until the end of the script.
>Solution :
It seems to me you could use any() rather than using a for loop:
if any(proc.name().lower() == name.lower() for proc in psutil.process_iter()):
print("found")
else
print("not found")