【问题标题】:How to read a txt and store its data in a list?如何读取 txt 并将其数据存储在列表中?
【发布时间】:2021-07-25 15:35:30
【问题描述】:
pathfile = "C:\Users\gk\Documents\toread"


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

我只是尝试将变量设为redfile

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

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

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

【问题讨论】:

    标签: react-graph-vis


    【解决方案1】:

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

    pathfile = "C:\Users\gk\Documents\toread"
    
    
    readfile= open(pathfile+'.txt', 'r')
    
    
    newList = []
    
    for i in readfile:
            newList.append(i)
    readfile.close()
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 2021-01-18
      • 2015-07-19
      相关资源
      最近更新 更多