。這是我的程序Python的IndexError超出範圍
#!/usr/bin/python
import sys
fn=sys.argv[1]
dt=open(fn).readlines()
for ln in dt:
fd=ln.split()
cntw=fd[1].count("W")
print cntw
它完全讀取該文件,但在最後給出了錯誤:
Traceback (most recent call last):
File "./task0.py", line 7, in <module>
cntw=fd[1].count("W")
IndexError: list index out of range
這是爲什麼,什麼我需要改變嗎?
點,如果你告訴我們,文件的內容,將是很好的 – Hackaholic 2014-11-06 20:59:33