Created
July 20, 2012 07:28
-
-
Save jsyeo/3149284 to your computer and use it in GitHub Desktop.
Python Script To Print Current Laptop Battery Power
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
def main(): | |
power_now = open("/sys/class/power_supply/BAT0/energy_now", "r").readline() | |
power_full = open("/sys/class/power_supply/BAT0/energy_full", "r").readline() | |
print float(power_now)/float(power_full) * 100 , "%" | |
if __name__ == "__main__": | |
main() |
Check and see if you have this file to get the percentage directly: /sys/class/power_supply/BAT0/capacity
i got this error...
FileNotFoundError Traceback (most recent call last)
in
----> 1 power_now = open("/sys/class/power_supply/BAT0/energy_now", "r").readline()
2 power_full = open("/sys/class/power_supply/BAT0/energy_full", "r").readline()
3 print (float(power_now)/float(power_full) * 100 , "%")
FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/power_supply/BAT0/energy_now'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, on my system the energy_now file is called charge_now, I see you wrote this 7 years ago. Thanks for sharing.