In Python, how can I detect whether the computer is on battery power?
The most reliable way to retrieve this information in C is by using GetSystemPowerStatus.If no battery is present ACLineStatus will be set to 128 til exposes this information under Linux, Windows and FreeBSD, so to check if battery is present you can do this >>> import psutil >>> has_battery = psutil.sensors_battery() is not None