Python错误:indexerror:列表索引超出范围 [英] Python error :indexerror: list index out of range
本文介绍了Python错误:indexerror:列表索引超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
f = open(pdbID,'r')
k = 0
data = f.readlines()
g = open(dump,' w')
for linedata in data:
line = linedata.strip()
words = line.split()
if(words [12] =='4') :
k = k + 1
g.write(linedata)
if(words [12] =='4') :
IndexError:列表索引超出范围
我尝试过:
我被困在代码的这一部分,我无法前进
解决方案
Quote:IndexError:列表索引超出范围
确保数组字中至少有12项
f = open (pdbID,'r') k = 0 data = f.readlines() g = open (dump, 'w') for linedata in data: line=linedata.strip() words = line.split() if (words[12] == '4'): k=k+1 g.write(linedata)
if (words[12] == '4'):
IndexError: list index out of range
What I have tried:
I am stuck at this part of the code and I can not move forward
解决方案
Quote:IndexError: list index out of range
Make sure you have at least 12 items in arraywords
.
这篇关于Python错误:indexerror:列表索引超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文