树莓派02-获取CPU温度

pi@raspberrypi ~ $ cat temperature.py
#! /usr/bin/python
#-*- coding: utf-8 -*-
#open file
file = open("/sys/class/thermal/thermal_zone0/temp")
#读取结果,并转换为浮点数
temp = float(file.read())/1000
#关闭文件
file.close()
#向控制台打印
print "temp : %.1f" %temp

pi@raspberrypi ~ $ ./temperature.py
temp : 42.2

 

原文链接如下:http://bbs.ickey.cn/group-topic-id-35431.html

 

posted @ 2015-11-13 15:28  qingfengxuxu  阅读(361)  评论(0)    收藏  举报