我的代码需要很长时间才能运行,我不想一直盯着它,但想知道它什么时候完成。
我怎样才能使(Python)代码在完成时发出“警报”?我正在考虑让它在代码结束时播放一个.wav文件……
这个想法可行吗? 如果是,我该怎么做呢?
我的代码需要很长时间才能运行,我不想一直盯着它,但想知道它什么时候完成。
我怎样才能使(Python)代码在完成时发出“警报”?我正在考虑让它在代码结束时播放一个.wav文件……
这个想法可行吗? 如果是,我该怎么做呢?
当前回答
Ubuntu语音调度器可以使用:
import subprocess
subprocess.call(['speech-dispatcher']) #start speech dispatcher
subprocess.call(['spd-say', '"your process has finished"'])
其他回答
import subprocess
subprocess.call(['D:\greensoft\TTPlayer\TTPlayer.exe', "E:\stridevampaclip.mp3"])
这个似乎在Windows和Linux上都可以运行*(从这个问题来看):
def beep():
print("\a")
beep()
在Windows中,可以在末尾放置:
import winsound
winsound.Beep(500, 1000)
where 500 is the frequency in Herz
1000 is the duration in miliseconds
要在Linux上工作,你可能需要做以下事情(来自QO的评论):
在终端中,输入'cd /etc/modprobe。然后输入gksudo gedit blacklist.conf 注释一行说“黑名单pcspkr”,然后重新启动 还要检查终端首选项是否选中了“终端铃声”。
它可以通过如下代码来完成:
import time
time.sleep(10) #Set the time
for x in range(60):
time.sleep(1)
print('\a')
我创建了一个python模块,在代码执行后提醒Telegram应用程序上的开发人员。这可能比发出警报声音更有帮助。
Pypi链接: https://pypi.org/project/devreminder/
Github链接: https://github.com/cagataygulten/devreminder
例子:
In [1]>>
from devreminder import DevReminder
import time
In [2]>>
remind = DevReminder(1932126911,False,0)
In [3]>>
remind.me("Example")
time.sleep(6)
输出:
请按照README文件了解更多信息。
在macOS上有一个非常简单的方法来做到这一点。
python file.py && say done