我本打算贴一个例子,但我说去死吧,我只是把我的东西贴出来。对我放松点。我习惯了红宝石。Python对我来说是全新的。在
我有一个叫做que的文件,里面有一堆歌。我想做一个背景线,不断检查,看看奎有没有任何歌曲。如果其中有歌曲,则播放第一行的歌曲,然后删除第一行。(.que.swp公司). 在
现在的问题是,我不知道如何在后台完成这些。我有另一个类,它允许用户向que文件添加歌曲。所以他们需要同时运行。在
class MusicPlayer(threading.Thread):
def __init__(self):
super(MusicPlayer, self).__init__()
self.que_file = "que"
self.playQue()
def playQue(self):
while 1:
try:
f = open(self.que_file, "r")
songUp = f.readline()
songUp = songUp.rstrip()
cmd = "cvlc \"%s\" vlc://quit &>/dev/null" % (songUp)
os.system(cmd)
data="".join(open(self.que_file).readlines()[1:-1])
open(".que.swp","wb").write(data)
os.remove(self.que_file)
os.rename(".que.swp", self.que_file)
print "\n%s added %s to the que" % (self.user, self.dir)
except:
print "No Que File Exists"
time.sleep(1)
#main#
if __name__ == '__main__':
player = MusicPlayer()
player.start()
print "helloWorld"
“地狱世界”从不打印到终端。它一直在我的课上循环。 如果这能让你感觉好一点,你可以清理我的任何难看的命令。记住我是新来的。我已经在这里呆了几个小时了,只好问了。在
循环不是从
player.start()
行开始的,而是从以下行开始:这是因为您在
__init__
中调用了self.playQue()
。如果删除该行,并将方法playQue
更改为run
,则该线程应该单独运行。在有关}的说明,请参见instructions for the threading package:
start
和{相关问题 更多 >
编程相关推荐