意外输出避免尝试/除外

时间:2016-04-29 20:50:00

标签: eclipse python-3.x unix pydev gnome-terminal

我写了这段代码,用来检查设备是否是RPI并输出温度。

import os

def CheckIfPi():
    try:
        res = os.popen('vcgencmd measure_temp').readline()
        return float((res.replace("temp=","").replace("'C\n","")))
    except:
        return 0

def ReturnTemperature():
    if CheckIfPi() > 0:
        print("The temperature of the Pi is: ", CheckIfPi())
    else:
        print("This is not a Pi.")


ReturnTemperature()

我得到的输出:

/bin/sh: 1: vcgencmd: not found
This is not a Pi.

我没想到的输出是/bin/sh: 1: vcgencmd: not found

0 个答案:

没有答案