gpt4 book ai didi

php - 从python脚本获取变量到php页面

转载 作者:行者123 更新时间:2023-12-02 04:21:44 24 4
gpt4 key购买 nike

我的 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" }

可以只提取温度和湿度吗?

最佳答案

您可以将它添加到您的代码中,并在运行它时添加两个文件,例如: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()

关于php - 从python脚本获取变量到php页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59339922/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com