Python: AttributeError: '_io.TextIOWrapper' object has no attribute 'split'

前端 未结 3 1534
清歌不尽
清歌不尽 2020-11-29 03:36

I have a textfile, let\'s call it goodlines.txt and I want to load it and make a list that contains each line in the text file.

I tried using the

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 03:59

    Try this:

     >>> f = open('goodlines.txt')
     >>> mylist = f.readlines()
    

    open() function returns a file object. And for file object, there is no method like splitlines() or split(). You could use dir(f) to see all the methods of file object.

提交回复
热议问题