从python脚本获取变量到php pag

2024-06-01 13:23:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我的Python脚本返回:

python /home/pi/sht/sht31.py
False
True
False
Temperature: 8.10668945312
Humidity: 83.49609375

我需要在index.php中打印湿度和温度

我试过:

exec('sudo python /home/pi/sht/sht31.py' , $output);
var_dump($output);

但输出是:

array(5) { [0]=> string(5) "False" [1]=> string(4) "True" [2]=> string(5) "False" [3]=>       string(26) "Temperature: 8.07464599609" [4]=> string(23) "Humidity: 83.5327148438" }

是否可以只提取温度和湿度


Tags: py脚本falsetruehomeoutputstringindex
2条回答

您可以将它添加到代码中,并在运行它时添加两个文件,例如:python ex0.py ex0.txt ex1.txt我希望这会有所帮助,如果它不抱歉,祝您度过愉快的一天

from sys import argv
from os.path import exists

script, from_file, to_file = argv 
print ("Copying from %s to %s.") % (from_file, to_file)

in_file=open(from_file)
indata= in_file.read()

相关问题 更多 >