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

pathfile = "C:UsersgkDocumentstoread"


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

我试着把一个变量作为 redfile

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

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

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

回答

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

pathfile = "C:UsersgkDocumentstoread"


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


newList = []

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


以上是如何读取txt并将其数据存储在列表中?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>