Help in pure Python code
-
wrote on 5 Feb 2019, 08:50 last edited by monamour 2 May 2019, 09:03
Dear all,
I have the list for all the computer names in my network (FIVE COMPUTERS) in a text file which name is "computers.txt".
I have written the code below to pass all the computer names in the text file by using
the first loop and execute the command "Win32_NetworkAdapter()" which will fetch certain
information by using the second loop.The problem is that the code loop only locally in my pc not in the text file "computers". This is the output:
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000*** I am using Python 3.7.**
The code
import wmi from multiprocessing import Process import win32com.client def pcs(): qbfile = open("computers.txt", "r") c = wmi.WMI () for aline in qbfile: for s in c.Win32_NetworkAdapter(): if s.Manufacturer == "Intel" and s.Speed == "1000000000": print ("The PC is " +s.SystemName +" and the Speed is " +s.Speed ) #qbfile.close() if __name__ == '__main__': Process(target=pcs).start()
Thanks in advance.
-
Dear all,
I have the list for all the computer names in my network (FIVE COMPUTERS) in a text file which name is "computers.txt".
I have written the code below to pass all the computer names in the text file by using
the first loop and execute the command "Win32_NetworkAdapter()" which will fetch certain
information by using the second loop.The problem is that the code loop only locally in my pc not in the text file "computers". This is the output:
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000*** I am using Python 3.7.**
The code
import wmi from multiprocessing import Process import win32com.client def pcs(): qbfile = open("computers.txt", "r") c = wmi.WMI () for aline in qbfile: for s in c.Win32_NetworkAdapter(): if s.Manufacturer == "Intel" and s.Speed == "1000000000": print ("The PC is " +s.SystemName +" and the Speed is " +s.Speed ) #qbfile.close() if __name__ == '__main__': Process(target=pcs).start()
Thanks in advance.
Lifetime Qt Championwrote on 5 Feb 2019, 09:12 last edited by jsulm 2 May 2019, 09:13@monamour Your question is completely unrelated to Qt, but I will try to answer.
You are using a relative path:qbfile = open("computers.txt", "r")
Depending on current working directory it will not work as it will not find the file.
Also this is not clear: "The problem is that the code loop only locally in my pc not in the text file "computers". What do you mean by that? -
@monamour Your question is completely unrelated to Qt, but I will try to answer.
You are using a relative path:qbfile = open("computers.txt", "r")
Depending on current working directory it will not work as it will not find the file.
Also this is not clear: "The problem is that the code loop only locally in my pc not in the text file "computers". What do you mean by that?wrote on 5 Feb 2019, 09:15 last edited by@jsulm Thanks for replying. Actually, I have searched for exact subject in this forum then I read it "General and Desktop". However, the question is not related to the QT, it is pure python.
The directory is current directory.
Many thanks,
-
@jsulm Thanks for replying. Actually, I have searched for exact subject in this forum then I read it "General and Desktop". However, the question is not related to the QT, it is pure python.
The directory is current directory.
Many thanks,
@monamour said in Help in pure Python code:
The directory is current directory
is that file inside this directory?
-
Dear all,
I have the list for all the computer names in my network (FIVE COMPUTERS) in a text file which name is "computers.txt".
I have written the code below to pass all the computer names in the text file by using
the first loop and execute the command "Win32_NetworkAdapter()" which will fetch certain
information by using the second loop.The problem is that the code loop only locally in my pc not in the text file "computers". This is the output:
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000
The PC is mycomputername and the Speed is 1000000000*** I am using Python 3.7.**
The code
import wmi from multiprocessing import Process import win32com.client def pcs(): qbfile = open("computers.txt", "r") c = wmi.WMI () for aline in qbfile: for s in c.Win32_NetworkAdapter(): if s.Manufacturer == "Intel" and s.Speed == "1000000000": print ("The PC is " +s.SystemName +" and the Speed is " +s.Speed ) #qbfile.close() if __name__ == '__main__': Process(target=pcs).start()
Thanks in advance.
wrote on 5 Feb 2019, 09:33 last edited by@monamour said in Help in pure Python code:
for aline in qbfile: for s in c.Win32_NetworkAdapter():
Your code does not even attempt to access the
aline
line returned out of the file. It simply loops throughc.Win32_NetworkAdapter()
each time there is a line in your file. That is why you are seeing the output you get. Whatever your code is supposed to do with the linealine
you need to make it do it.... -
@monamour said in Help in pure Python code:
The directory is current directory
is that file inside this directory?
-
@monamour said in Help in pure Python code:
for aline in qbfile: for s in c.Win32_NetworkAdapter():
Your code does not even attempt to access the
aline
line returned out of the file. It simply loops throughc.Win32_NetworkAdapter()
each time there is a line in your file. That is why you are seeing the output you get. Whatever your code is supposed to do with the linealine
you need to make it do it.... -
wrote on 6 Feb 2019, 12:55 last edited by monamour 2 Jun 2019, 12:56
Dear All,
It has been solved. The problem was the function **"strip()"** which remove the spaces between the characters in the text file "computers.txt".
Many thanks,
-
Dear All,
It has been solved. The problem was the function **"strip()"** which remove the spaces between the characters in the text file "computers.txt".
Many thanks,
wrote on 6 Feb 2019, 18:46 last edited by JonB 2 Jun 2019, 18:46@monamour
In the code you asked about there is no call to anystrip()
function, and the code simply does not access the characters read from the file, whether you remove anything from them or not. So your solution is interesting.
1/9