Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Help in pure Python code
Forum Update on Monday, May 27th 2025

Help in pure Python code

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 990 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    monamour
    wrote on 5 Feb 2019, 08:50 last edited by monamour 2 May 2019, 09:03
    #1

    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.

    J J 2 Replies Last reply 5 Feb 2019, 09:12
    0
    • M monamour
      5 Feb 2019, 08:50

      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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 5 Feb 2019, 09:12 last edited by jsulm 2 May 2019, 09:13
      #2

      @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?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 5 Feb 2019, 09:15
      3
      • J jsulm
        5 Feb 2019, 09:12

        @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?

        M Offline
        M Offline
        monamour
        wrote on 5 Feb 2019, 09:15 last edited by
        #3

        @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,

        J 1 Reply Last reply 5 Feb 2019, 09:17
        0
        • M monamour
          5 Feb 2019, 09:15

          @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,

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 5 Feb 2019, 09:17 last edited by
          #4

          @monamour said in Help in pure Python code:

          The directory is current directory

          is that file inside this directory?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          M 1 Reply Last reply 5 Feb 2019, 13:49
          0
          • M monamour
            5 Feb 2019, 08:50

            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.

            J Online
            J Online
            JonB
            wrote on 5 Feb 2019, 09:33 last edited by
            #5

            @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 through c.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 line aline you need to make it do it....

            M 1 Reply Last reply 5 Feb 2019, 13:50
            5
            • J jsulm
              5 Feb 2019, 09:17

              @monamour said in Help in pure Python code:

              The directory is current directory

              is that file inside this directory?

              M Offline
              M Offline
              monamour
              wrote on 5 Feb 2019, 13:49 last edited by
              #6

              @jsulm Yes, inside it.

              1 Reply Last reply
              0
              • J JonB
                5 Feb 2019, 09:33

                @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 through c.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 line aline you need to make it do it....

                M Offline
                M Offline
                monamour
                wrote on 5 Feb 2019, 13:50 last edited by
                #7

                @JonB Many thanks I will try.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  monamour
                  wrote on 6 Feb 2019, 12:55 last edited by monamour 2 Jun 2019, 12:56
                  #8

                  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,

                  J 1 Reply Last reply 6 Feb 2019, 18:46
                  0
                  • M monamour
                    6 Feb 2019, 12:55

                    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,

                    J Online
                    J Online
                    JonB
                    wrote on 6 Feb 2019, 18:46 last edited by JonB 2 Jun 2019, 18:46
                    #9

                    @monamour
                    In the code you asked about there is no call to any strip() 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 Reply Last reply
                    1

                    1/9

                    5 Feb 2019, 08:50

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved