簡體   English   中英

如何讀取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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM