首页 > 开发 > linux > 正文

利用python获取树莓派的温度

2017-07-06 10:40:32  来源:慕课网
# -*- coding: utf-8 -*-  # 打开文件  file = open("/sys/class/thermal/thermal_zone0/temp")  # 读取结果,并转换为浮点数  temp = float(file.read()) / 1000  # 关闭文件  file.close()  # 向控制台打印  print "temp : %.1f" %temp  

在temp.py目录下输入以下指令执行脚本

执行脚本

python temp.py

执行返回

temp : 49.2