Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python外观失败了,我不知道为什么:indexer错误:列表索引超出范围_Python_Loops_Index Error - Fatal编程技术网

Python外观失败了,我不知道为什么:indexer错误:列表索引超出范围

Python外观失败了,我不知道为什么:indexer错误:列表索引超出范围,python,loops,index-error,Python,Loops,Index Error,我为LIRC创建了一个强力红外爆炸机,但我循环命令的循环不断抛出索引失败,有什么想法吗: 它位于第48行,coms在comfile循环中: IndexError: list index out of range 我不知道为什么它不会循环然后转到下一个文件 import os import shutil import subprocess import time # Using readline() count = 0 #os.remove("list.list") os.system("to

我为LIRC创建了一个强力红外爆炸机,但我循环命令的循环不断抛出索引失败,有什么想法吗:

它位于第48行,coms在comfile循环中:

IndexError: list index out of range
我不知道为什么它不会循环然后转到下一个文件

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:

然后过滤掉空值,让它继续。

请将您的示例简化为a,并在您的问题中包含回溯。我们不知道第48行是什么(我不打算计数);comfile:中coms的
行肯定不会导致
索引器
。您有一个
打印(值[0])
“调试”调用。在使用这些变量之前,为什么不为
coms
comvalues
添加类似的变量呢?对不起,我不知道是否没有列出行号。在发布有关产生异常的代码的问题时,请始终包含完整的回溯-复制并粘贴它,然后将其格式化为代码(选择它并键入
ctrl-k
)。。并检查/打印套件中的相关数据
comand=comvalues[1]
-
comvalues
必须有少于2个项目/事物。在哪里添加该行?我想你的意思是
comvalues
?如果
comvalues
是非空字符串,但不包含任何空格,该怎么办?