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 Updated to NodeBB v4.3 + New Features

Help in pure Python code

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.0k 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.
  • monamourM Offline
    monamourM Offline
    monamour
    wrote on last edited by monamour
    #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.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • monamourM monamour

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #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

      monamourM 1 Reply Last reply
      3
      • jsulmJ jsulm

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

        monamourM Offline
        monamourM Offline
        monamour
        wrote on 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,

        jsulmJ 1 Reply Last reply
        0
        • monamourM monamour

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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

          monamourM 1 Reply Last reply
          0
          • monamourM monamour

            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.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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....

            monamourM 1 Reply Last reply
            5
            • jsulmJ jsulm

              @monamour said in Help in pure Python code:

              The directory is current directory

              is that file inside this directory?

              monamourM Offline
              monamourM Offline
              monamour
              wrote on last edited by
              #6

              @jsulm Yes, inside it.

              1 Reply Last reply
              0
              • JonBJ JonB

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

                monamourM Offline
                monamourM Offline
                monamour
                wrote on last edited by
                #7

                @JonB Many thanks I will try.

                1 Reply Last reply
                0
                • monamourM Offline
                  monamourM Offline
                  monamour
                  wrote on last edited by monamour
                  #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,

                  JonBJ 1 Reply Last reply
                  0
                  • monamourM monamour

                    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,

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #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

                    • Login

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