'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>>文件: 电池信息.py
>>作者: liu yang
>>邮箱: [email protected] ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #!/usr/bin/env python
# -*- coding: utf-8 -*- import sys,os
import psutil def battery_message():
ba=psutil.sensors_battery()
# 未充电:sbattery(percent=13, secsleft=4294967295, power_plugged=False)
# 在充电:sbattery(percent=14, secsleft= < BatteryTime.POWER_TIME_UNLIMITED: -2 >, power_plugged = True)
battery=ba.percent
if ba.power_plugged:
power="正在充电中..."
else:
power="未充电"
print('电量剩余:%d 电源状态:%6s'%(battery,power)) if __name__ == '__main__':
battery_message()