如何读取 txt 并将其数据存储在列表中?

How to read a txt and store its data in a list?

pathfile = "C:\Users\gk\Documents\toread"


readfile= open(pathfile+'.txt', 'r')

我只是尝试将变量设置为 redfile

newList = []
newList = readfile
readfile.close()

然后发送一个获取该列表的图表。

但是当我生成图表时,我只是得到一个 None。

尝试使用for循环将txt的每一行保存在新列表中

pathfile = "C:\Users\gk\Documents\toread"


readfile= open(pathfile+'.txt', 'r')


newList = []

for i in readfile:
        newList.append(i)
readfile.close()