怎么打开本地文件,然后把文件内容输出为列表?

怎么读取D盘中的text文件的数据(数据是一行行的),如下面截图;
然后转换成['000001.SZ','000009.SZ','000039.SZ']这种形式,并输出到本地

img


f = open('a.txt', 'r', encoding='utf-8')
d = f.read().split('\n')
f.close()
print(d)

img

img


如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢


_=[]
with open(r'D:/text.txt', 'r', encoding='utf-8') as f:
    txt=f.readline().replace('\n','')
    while txt:
        _.append(txt)
        txt = f.readline().replace('\n','')

print(_)

img

img