【发布时间】:2017-10-09 02:44:15
【问题描述】:
我的 Raspberry Pi 3 Model B 上有一个 Python 脚本(OS NOOBS),它在运行时每分钟将 CPU 的温度记录到一个 .csv 文件中。
我想知道的是如何从 Python 脚本打开终端并在终端中输出温度而不是将其记录到 .csv 文件中?
这是我目前写的代码:
from gpiozero import CPUTemperature
from time import sleep, strftime, time
cpu = CPUTemperature()
def output_temp(temp):
with open("cpu_temp.csv", "a") as log:
log.write("{0}, {1}\n".format(strftime("%Y-%m-%d %H:&M:%S"),str(temp)))
while True:
temp = cpu.temperature
output_temp(temp)
sleep(60)
我正计划使用我所要求的,所以当温度超过“x”度时,终端将打开,在那里打印温度,直到它再次降至“x”标记以下。但是,我会自己计算剩下的部分,因为我是一个仍在学习的新手。但是我卡在我想打开终端并在那里打印变量的部分。
我正在使用“Python 3 (IDLE)”软件来编写和运行这段代码。完成后我会集成它,以便它在启动时自动运行。
任何帮助将不胜感激! 真挚地, 乔克
【问题讨论】:
标签: python linux terminal output raspberry-pi3