用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)
1 个回答
0
正如@paul-seeb所说,一个选择里面可能有多个程序。我建议你先随机选择一个,然后再在里面挑选一个节目,如果你喜欢这样的话。
selections = [
'Doc McStuffins',
'Mickey Mouse Clubhouse',
...
'WordWorld',
]
selection = choice(selections)
shows = glob('D:\Recorded TV\{}*.wtv'.format(selection))
show = choice(shows)