Keep getting error 'list' object has no attribute 'split'

后端 未结 1 1771
一个人的身影
一个人的身影 2021-01-24 04:07

Keep getting this split error, when trying to split up my list Word by Word, line by line.

I got a file which contains links, +20000 links. These links is in a list call

相关标签:
1条回答
  • 2021-01-24 04:32

    First thing - as Martijn Pieters said, your indentation is off. Its hard to guess exactly what you mean, please fix it. But:

    paths = [line.strip().split('\t') for line in tsv]  
    

    line.split('\t') already returns a list. You put that list into path so path is a list of lists. You iterate over that list of lists here:

    for line in newPath:
       links.append(line[3:4])
    

    so links will also be a list of lists. And finally:

    for i in links:
       newList.append(i.split(';'))
    

    you try to call split for i - which is a list. split is a member function of str and does not exist for lists - hence your error.

    0 讨论(0)
提交回复
热议问题