Solved For loop problem!
-
@jsulm "The first if" should execute when the LINEDIT is blank. " The second if" will execute when the LINEDIT is NOT blank.
-
@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
-
@jsulm Yes, I edited the code. It is same, not solved.
-
-
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 Maybe both strings use different encodings?
-
@jsulm Means? because both of them are strings.
-
@jsulm If I make two for loops, it will work. What is the common sense in this ?
-
@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. -
This post is deleted! -
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