You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python词汇提醒程序报错:notification.notify内语法无效求助

问题排查与修复方案

嘿,我帮你找出代码里的几个关键问题啦,咱们一个个理清楚:

  • 参数间缺少逗号分隔:Python函数调用的多个参数必须用逗号隔开,你在notification.notify()里的title、The_word、Timeout这几行之间没加逗号,这直接触发了语法报错。
  • 参数名称错误:
    • plyer的notification.notify()函数并没有The_word这个参数,要展示单词内容,你需要用message参数;
    • Python是大小写敏感的,函数里的超时参数是小写的timeout,不是大写开头的Timeout。
  • 额外实用建议:你已经写了get_word()函数来返回大写的单词,直接复用它能让代码更整洁;另外别忘了给循环加2小时的延迟,不然代码会疯狂弹出通知!

下面是修复后的完整代码:

import random
from words import voc_list
import time
from plyer import notification

def get_word():
    word = random.choice(voc_list)
    return word.upper()

if __name__ == "__main__":
    while True:
        notification.notify(
            title="Here is another vocabulary word :-",
            message=get_word(),
            timeout=8
        )
        # 每2小时推送一次,换算成秒是2*60*60
        time.sleep(2 * 60 * 60)

内容的提问来源于stack exchange,提问作者Hardyk Mahendru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:28:22