dongneng5383 2019-05-28 19:43
浏览 316

在php中调用特定的python脚本不起作用

So i'm working on a project trying to turn on/off the light in my room using a webpage. I've created this python script which reads a file to get the state of the light(on or of) and then writes the 'opposite' back to the file.(this would basically toggle the light) If i now call this script in php with

system("python script.py")

it doesn't output anything to the page instead of the expected state(on or of)

f = open("lightState.txt", "r")
var = f.read(2)
f.close()


f = open("lightState.txt", "w")

state = ""


if(var == "of"):
    #turn light on
    state ="on"

if(var == "on"):
    #turn light off
    state = "of"

print(state)
f.write(state)
f.close()

i've also tried this with another python script in the same folder which worked perfectly fine.

Any help is apreciated

-SmRndmGy

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记