如何使函数与我的视图一起运行

2024-05-14 20:28:11 发布

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

我有这个功能,我想让它和我的观点一致,我怎么能做到呢?在

def PlaySound(self):
    while(True):
        if GPIO.input(Snare) == False:
        os.system("path/to/the/sound")
    return ("Is activated")

^{pr2}$

Tags: pathself功能falsetrueinputgpioif
1条回答
网友
1楼 · 发布于 2024-05-14 20:28:11

如果PlaySound不是类的方法,那么就不需要self。使用def PlaySound():。在

def PlaySound():
    ...

然后,在返回响应之前,可以在视图中调用该方法。在

^{pr2}$

相关问题 更多 >

    热门问题