提问人:arteagavskiy 提问时间:7/28/2022 最后编辑:The Thonnuarteagavskiy 更新时间:7/28/2022 访问量:341
在 Python 中将列表导出到 txt 文件 [duplicate]
exporting a list to a txt file in Python [duplicate]
问:
我想将该程序中获得的序列列表导出到 txt 文件。我该怎么做?
with open("example_val.txt") as f:
sequence = []
for line in f:
if line.startswith(""):
line = line[:-1]
seq = (line.split("<|endoftext|>")[1].split(':')[0] + ":")
output.write(seq)
sequence.append(seq)
print(seq)
输出:
ERRDLLRFKH:
RRDLLRFKHG:
RDLLRFKHGD:
DLLRFKHGDS:
LLRFKHGDSE:
LSPATRWGMI:
答:
2赞
doa4321
7/28/2022
#1
鉴于序列是字符串,只需执行
sequence = [i+"\n" for i in sequence]
with open("file.txt", "w+") as f:
f.writelines(sequence)
上一个:生成具有不同长度的序列
下一个:用整数序列替换每个字符
评论
with open("example_val.txt") as f, open("output.txt", "w") as wf:
wf.write()
seq