For loop problem!
-
@monamour Looks like you edited the code, because before both if were identical.
Actually you can do it like this:if proc.name() not in x: QMessageBox.information(self,"Error",'Blank!') return else: proc.kill() QMessageBox.information(self, "Success", x2 +"has been terminated" return
-
1- proc.name after "IF CONDITIONS"
input
print(x)
print(proc.name())Output
notepad.exe
notepad.exe2-The full proc.name after "FOR LOOP"
input
print(proc.name())
output
System Idle Process
System
svchost.exe
smss.exe
csrss.exe
MOM.exe
wininit.exe
csrss.exe
services.exe
lsass.exe
lsm.exe
python.exe
explorer.exe
svchost.exe
svchost.exe
chrome.exe
WSHelper.exe
cbInterface.exe
taskhost.exe
notepad.exe
PresentationFontCache.exe
SearchFilterHost.exe
chrome.exe
chrome.exe
designer.exe
thunderbird.exe
fsnotifier64.exe
conhost.exe
chrome.exe
svchost.exe
notepad++.exe
VSSVC.exe
pycharm64.exe
chrome.exe
chrome.exe
SearchProtocolHost.exe
conhost.exe
chrome.exeProcess finished with exit code 0
-
@monamour said in For loop problem!:
Means? because both of them are strings
I mean different string encodings like Latin1, UTF-8, ...
Can you try to print out type(x) and type(proc.name())?
"If I make two for loops, it will work. What is the common sense in this ?" - I don't know what you mean. -
for proc in psutil.process_iter(): if proc.name()==x: proc.kill() QMessageBox.information(self, "Success", x2 +"has been terminated") return for proc in psutil.process_iter(): if proc.name()!=x: QMessageBox.information(self, "Error","The process " +x2 + " is not found") return