簡體   English   中英

Python 看起來失敗了,我不知道為什么:IndexError: list index out of range

[英]Python look is failing and I dont know why: IndexError: list index out of range

我為 LIRC 創建了一個蠻力 IR blaster,但是我循環通過命令的循環不斷拋出索引失敗,任何想法:

它在第 48 行,comfile 循環中的 coms:

IndexError: list index out of range

我不知道為什么它不會循環然后 go 到下一個文件。

import os
import shutil
import subprocess
import time
# Using readline() 
count = 0
#os.remove("list.list")
os.system("touch /home/pi/com.list")
os.system("touch /home/pi/list.list")
os.system("systemctl start lircd")
for filename in os.listdir('confs'):
    currconf = "/home/pi/confs/" + filename
    print "**********start*******"
    print "1. ", filename
    #print "2. ", currconf
    #os.system("systemctl stop lircd")
    #subprocess.call('systemctl stop lircd', shell=True)
    shutil.move(currconf, "/etc/lirc/lircd.conf")


    subprocess.call('systemctl reset-failed lircd', shell=True)
    subprocess.call('systemctl restart lircd', shell=True)
    time.sleep(1)
    subprocess.call('systemctl status lircd | tail -3', shell=True)
   # os.system("systemctl start lircd")
   # irlist  = ""
    #print "3. ", irlist
    os.remove("/home/pi/list.list")
    os.remove("/home/pi/com.list")
    os.system('irsend list \"\" \"\" >> /home/pi/list.list')



    qbfile = open("/home/pi/list.list", "r")

    for aline in qbfile:
        values = aline.split()  
        print(values[0])

        rname = values[0].strip('\n')
        print "2. rname", rname
        comlist = 'irsend list ' + rname + ' \"\" >> /home/pi/com.list'
        print "3. comlist", comlist
        os.system(comlist)
        comfile = open("/home/pi/com.list", "r")
        for coms in comfile:
            comvalues = coms.split()  
            comand = comvalues[1]#.strip('\n')
            cmd =  "irsend SEND_ONCE " + rname + " " + comand
            print "4. cmd ", cmd
            time.sleep(.001)
            os.system(cmd)
    print "**********end*******"

添加了一個

If comsvalue:

這過濾掉了 null 值並讓它繼續。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM