Warm tip: This article is reproduced from serverfault.com, please click

其他-无法在python中显示随机单词

(其他 - Not able to display random words in python)

发布于 2020-11-29 05:34:41
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 vocablary word :-"
        The_word = random.choice(voc_list)
        Timeout = 8
        )
    
    
    
    

我正尝试发出词汇提醒,每2小时告诉你一个新单词。我列出了单词及其含义,并想随机显示我从单词import voc_list中使用的任何单词,但是为什么这里显示为无效语法The_word = random.choice(voc_list)

Questioner
Hardyk Mahendru
Viewed
0
Abhinav Sharma 2020-11-29 13:52:54

我认为你在notify方法中传递了多个参数,并且缺少参数的逗号。

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 vocablary word :-",
        The_word = random.choice(voc_list),
        Timeout = 8
        )

如果你正确使用了导入的模块,则应该可以使用。