我使用以下代码段在python中读取文件:
with open ("data.txt", "r") as myfile: data=myfile.readlines()
输入文件为:
LLKKKKKKKKMMMMMMMMNNNNNNNNNNNNN GGGGGGGGGHHHHHHHHHHHHHHHHHHHHEEEEEEEE
当我打印数据时
['LLKKKKKKKKMMMMMMMMNNNNNNNNNNNNN\n', 'GGGGGGGGGHHHHHHHHHHHHHHHHHHHHEEEEEEEE']
如我所见,数据是list形式化的。如何将其制成字符串?而且我怎么删除"\n","["以及"]"从中字符?
"\n","["
"]"
你可以使用:
with open('data.txt', 'r') as file: data = file.read().replace('\n', '')