用Python脚本打开一个随机文件

2024-09-30 00:23:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Python脚本,我的家人用它在我们的媒体中心随机播放一个儿童电视节目。我妻子告诉我,这个节目似乎喜欢同样的选秀节目。有没有办法让它更随机,让它从一些不同的选项中选择?在

提前谢谢。在

以下是我当前使用的:

import glob,random,os
files = glob.glob("D:\Recorded TV\Bubble Guppies*.wtv")
files.extend(glob.glob("D:\Recorded TV\Doc McStuffins*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Mickey Mouse Clubhouse*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Octonauts*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Team Umizoomi*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Jake and the Never Land Pirates*.wtv"))
files.extend(glob.glob("D:\Recorded TV\PAW Patrol*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Yo Gabba Gabba*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Henry Hugglemonster*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Wallykazam*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Dora the Explorer*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Jungle Junction*.wtv"))
files.extend(glob.glob("D:\Recorded TV\Little Einstein*.wtv"))
files.extend(glob.glob("D:\Recorded TV\The Wonder Pets*.wtv"))
files.extend(glob.glob("D:\Recorded TV\WordWorld*.wtv"))
file = random.choice(files)
print "Opening file %s..." % file
cmd = "rundll32 url.dll,FileProtocolHandler \"" + file + "\""
os.system(cmd)

Tags: the脚本cmdos家人randomfilestv
1条回答
网友
1楼 · 发布于 2024-09-30 00:23:28

正如@paulseeb所说,在一个选择中可能有更多的程序。如果你喜欢的话,我会先随机挑选一个节目,然后在那里表演。在

selections = [
    'Doc McStuffins',
    'Mickey Mouse Clubhouse',
    ...
    'WordWorld',
]
selection = choice(selections)
shows = glob('D:\Recorded TV\{}*.wtv'.format(selection))
show = choice(shows)

相关问题 更多 >

    热门问题