2014-07-21 36 views
1

我有一個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

在你的'random.choice()'調用之前嘗試'random.seed()'。這將根據系統時間(僞隨機值)播種「隨機」流。 – CoryKramer

+1

這看起來像是一個概率問題,而不是其他任何事情。我的猜測是某些節目比其他節目有更多的節目?或者更頻繁地選擇同一集? –

+1

這裏也可能有心理問題,例如確認偏見。您可以考慮保留最近播放的劇集(甚至是節目)的清單,並在重新挑選時放棄它們。 – jonrsharpe

回答

0

正如@保羅 - 馬斯喀特說,有可能是在一個選擇多個程序。我首先隨機選擇一個選擇,然後在那裏展示,如果這是你喜歡的。

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

感謝大家的好評。我非常喜歡首先選擇選擇的想法。某些節目肯定有更多的節目。我的妻子告訴我,這似乎有利於大約20集超過250 +。我會嘗試選擇路線,看看會發生什麼。 – aldi32

相關問題