简体   繁体   English

使用Python脚本打开随机文件

[英]Open a random file with Python Script

I have a Python Script that my family uses to play a random kid's TV show on our Media Center. 我有一个Python脚本,家人可以在我们的媒体中心上播放随机播放的孩子的电视节目。 My wife tells me that the program seems to favor the same selection of shows. 我的妻子告诉我,该节目似乎偏爱相同的节目选择。 Is there a way to make it more random so that it picks from some different options? 有没有办法使它更具随机性,以便从某些不同的选项中进行选择?

Thanks in advance. 提前致谢。

Here is what I am currently using: 这是我目前正在使用的:

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)

As @paul-seeb said, there are probably more programs in one selection. 正如@ paul-seeb所说,一个选择中可能有更多的程序。 I'd first randomly pick a selection and then a show there if that's what you prefer. 我会首先随机选择一个选项,然后在那儿放映(如果您愿意)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM