How to get battery percentage with python? [duplicate]
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.
python python-3.x battery
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.
add a comment |
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.
python python-3.x battery
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.
add a comment |
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.
python python-3.x battery
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
python python-3.x battery
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.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
Why are you parsing the string when the object has those attributes ? You just needbattery.percent
andbattery.power_plugged
.
– Mad Physicist
Aug 11 '17 at 13:33
Good point. I will change it soon
– whackamadoodle3000
Aug 11 '17 at 15:00
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
Why are you parsing the string when the object has those attributes ? You just needbattery.percent
andbattery.power_plugged
.
– Mad Physicist
Aug 11 '17 at 13:33
Good point. I will change it soon
– whackamadoodle3000
Aug 11 '17 at 15:00
add a comment |
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
Why are you parsing the string when the object has those attributes ? You just needbattery.percent
andbattery.power_plugged
.
– Mad Physicist
Aug 11 '17 at 13:33
Good point. I will change it soon
– whackamadoodle3000
Aug 11 '17 at 15:00
add a comment |
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
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
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 needbattery.percent
andbattery.power_plugged
.
– Mad Physicist
Aug 11 '17 at 13:33
Good point. I will change it soon
– whackamadoodle3000
Aug 11 '17 at 15:00
add a comment |
Why are you parsing the string when the object has those attributes ? You just needbattery.percent
andbattery.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
add a comment |