Python3 Error: list index out of range
f = open ('userinfo.txt')#flie_ad
lines = f.readlines()
num_f = 0
num_m = 0
for i in lines:
name = i.split(',')[0]
birthday = i.split(',')[1]
print(name,birthday)
if i.split(',')[2] == 'male':
num_m = num_m+1
else:
num_f = num_f +1
print ("There is %d male emp" %num_m)
print ("There is %d emp in this office" %(num_m+num_f))
userinfo.txt
fox,1995,male,
hanmeimei,1990,female,
liming,1989,male,
asdf,1995,female,
执行结果为
fox 1995
hanmeimei 1990
liming 1989
asdf 1995
Traceback (most recent call last):
Flie "test.py", line 14, in <module>
birthday = i.split(',')[1]
IndexError: list index out of range
这个报错无法理解 15行print已经成功输出了 反过头说14行超限了
python版本是3.5.0
系统是Red Hat Enterprise Linux 6
用vim编译
...全文


