Help in pure Python code
-
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.
-
@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 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.... -