How to get battery percentage with python? [duplicate]












1
















This question already has an answer here:




  • Getting Battery Capacity Windows with Python

    2 answers




How to get battery percentage with python?

Maybe some win32api functions may help.










share|improve this question















marked as duplicate by Mad Physicist, Alexander, Paolo, Cody Gray Aug 11 '17 at 10:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    1
















    This question already has an answer here:




    • Getting Battery Capacity Windows with Python

      2 answers




    How to get battery percentage with python?

    Maybe some win32api functions may help.










    share|improve this question















    marked as duplicate by Mad Physicist, Alexander, Paolo, Cody Gray Aug 11 '17 at 10:21


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      1












      1








      1


      0







      This question already has an answer here:




      • Getting Battery Capacity Windows with Python

        2 answers




      How to get battery percentage with python?

      Maybe some win32api functions may help.










      share|improve this question

















      This question already has an answer here:




      • Getting Battery Capacity Windows with Python

        2 answers




      How to get battery percentage with python?

      Maybe some win32api functions may help.





      This question already has an answer here:




      • Getting Battery Capacity Windows with Python

        2 answers








      python python-3.x battery






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 11 '17 at 4:27









      Mad Physicist

      36.6k1671102




      36.6k1671102










      asked Aug 11 '17 at 4:25









      Black ThunderBlack Thunder

      2,2553931




      2,2553931




      marked as duplicate by Mad Physicist, Alexander, Paolo, Cody Gray Aug 11 '17 at 10:21


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Mad Physicist, Alexander, Paolo, Cody Gray Aug 11 '17 at 10:21


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          10














          Try this:



          import psutil
          battery = psutil.sensors_battery()
          plugged = battery.power_plugged
          percent = str(battery.percent)
          if plugged==False: plugged="Not Plugged In"
          else: plugged="Plugged In"
          print(percent+'% | '+plugged)


          Library link is here. And check out this






          share|improve this answer


























          • Why are you parsing the string when the object has those attributes ? You just need battery.percent and battery.power_plugged.

            – Mad Physicist
            Aug 11 '17 at 13:33













          • Good point. I will change it soon

            – whackamadoodle3000
            Aug 11 '17 at 15:00


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          10














          Try this:



          import psutil
          battery = psutil.sensors_battery()
          plugged = battery.power_plugged
          percent = str(battery.percent)
          if plugged==False: plugged="Not Plugged In"
          else: plugged="Plugged In"
          print(percent+'% | '+plugged)


          Library link is here. And check out this






          share|improve this answer


























          • Why are you parsing the string when the object has those attributes ? You just need battery.percent and battery.power_plugged.

            – Mad Physicist
            Aug 11 '17 at 13:33













          • Good point. I will change it soon

            – whackamadoodle3000
            Aug 11 '17 at 15:00
















          10














          Try this:



          import psutil
          battery = psutil.sensors_battery()
          plugged = battery.power_plugged
          percent = str(battery.percent)
          if plugged==False: plugged="Not Plugged In"
          else: plugged="Plugged In"
          print(percent+'% | '+plugged)


          Library link is here. And check out this






          share|improve this answer


























          • Why are you parsing the string when the object has those attributes ? You just need battery.percent and battery.power_plugged.

            – Mad Physicist
            Aug 11 '17 at 13:33













          • Good point. I will change it soon

            – whackamadoodle3000
            Aug 11 '17 at 15:00














          10












          10








          10







          Try this:



          import psutil
          battery = psutil.sensors_battery()
          plugged = battery.power_plugged
          percent = str(battery.percent)
          if plugged==False: plugged="Not Plugged In"
          else: plugged="Plugged In"
          print(percent+'% | '+plugged)


          Library link is here. And check out this






          share|improve this answer















          Try this:



          import psutil
          battery = psutil.sensors_battery()
          plugged = battery.power_plugged
          percent = str(battery.percent)
          if plugged==False: plugged="Not Plugged In"
          else: plugged="Plugged In"
          print(percent+'% | '+plugged)


          Library link is here. And check out this







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 11 '17 at 15:02

























          answered Aug 11 '17 at 4:42









          whackamadoodle3000whackamadoodle3000

          4,72841331




          4,72841331













          • Why are you parsing the string when the object has those attributes ? You just need battery.percent and battery.power_plugged.

            – Mad Physicist
            Aug 11 '17 at 13:33













          • Good point. I will change it soon

            – whackamadoodle3000
            Aug 11 '17 at 15:00



















          • Why are you parsing the string when the object has those attributes ? You just need battery.percent and battery.power_plugged.

            – Mad Physicist
            Aug 11 '17 at 13:33













          • Good point. I will change it soon

            – whackamadoodle3000
            Aug 11 '17 at 15:00

















          Why are you parsing the string when the object has those attributes ? You just need battery.percent and battery.power_plugged.

          – Mad Physicist
          Aug 11 '17 at 13:33







          Why are you parsing the string when the object has those attributes ? You just need battery.percent and battery.power_plugged.

          – Mad Physicist
          Aug 11 '17 at 13:33















          Good point. I will change it soon

          – whackamadoodle3000
          Aug 11 '17 at 15:00





          Good point. I will change it soon

          – whackamadoodle3000
          Aug 11 '17 at 15:00



          Popular posts from this blog

          Homophylophilia

          Updating UILabel text programmatically using a function

          Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage