How to skip a empty line in text file using python

后端 未结 4 1518
一生所求
一生所求 2021-01-29 08:51

I have a text file as below.

  l[0]l[1]l[2]l[3]l[4]l[5]l[6]
-----------------------------------
1| abc is a book and cba too
2| xyz is a pencil and zyx too
3| de         


        
4条回答
  •  遥遥无期
    2021-01-29 09:28

    You can verify the list length at the beginning of your for loop and then continue if there is no 3rd element:

    if len(l)< 3: continue

    PS. Of course, you have to l.split() the line first, otherwise you will access single characters only.

提交回复
热议问题