我写了一个小代码,可以扫描空中的wifi信号,并根据数量播放一个或另一个音频文件。
停止在python中打开VLC
import time
import subprocess
import os
while True:
output = subprocess.Popen("airport en1 -s", shell=True, stdout=subprocess.PIPE).stdout.read()
lines = output.split('\n')
n = len(lines)
if n < 10:
print os.path.exists('/Users/shirin/Desktop/wifi/1.mp3')
p = subprocess.Popen(['/Applications/VLC.app/Contents/MacOS/VLC','/Users/shirin/Desktop/wifi/1.mp3'])
elif n > 10:
print os.path.exists('/Users/shirin/Desktop/wifi/1.mp3')
p = subprocess.Popen(['/Applications/VLC.app/Contents/MacOS/VLC','/Users/shirin/Desktop/wifi/1.mp3'])
现在我的问题是,当我通过终端运行该文件它保持一遍又一遍运行代码再次,我不知道如何阻止它。当我关闭终端时,它也不会停止。 所以我的问题: 我如何告诉python运行一次代码,然后停止?
已经非常感谢!
为什么'while while True:'? – Trompa
如果你只想运行一次,不要使用while循环 –
这段代码在哪里坐循环呢?我将复制的代码粘贴在一起,这从来都不聪明,我知道,但我是一个newby – malina