Jupyter 程序运行"成功/报错"具有声音提示的模板

利用Jupyter进行数据批量处理的时候,有时耗时较长,希望利用这段时间去做其他事情,想通过声音提示来判断Jupyter的程序运行状态,运行成功/报错则弹出相应提示音。
实现思路是先创建播放提示声音的函数,在需要提示的代码部分添加try except判断运行状态,实现代码的模板如下:

from IPython.display import Audio, display
def tip_error():
  display(Audio(url='https://www.feffery.club/error.mp3', autoplay=True))
def tip_success():
  display(Audio(url='https://www.feffery.club/success.mp3', autoplay=True))
try:
    """ 
    // 编写运行代码 //
    """
    tip_success()
except Exception as e:
    print(e)
    tip_error()

Jupyter notebook 效果举例

posted @ 2020-05-08 14:13  lqqgis  阅读(1166)  评论(0编辑  收藏  举报