我有一个名为path_text.txt
的文件,其内容是由换行符分隔的两个字符串:
/gp/oi/eu/gatk/inputs/NA12878_24RG_med.hg38.bam
/gp/oi/eu/gatk/inputs/NA12878_24RG_small.hg38.bam
我想要一个json数组对象,如下所示:
["/gp/oi/eu/gatk/inputs/NA12878_24RG_med.hg38.bam","/gp/oi/eu/gatk/inputs/NA12878_24RG_small.hg38.bam"]
我试过这样的方法:
with open('path_text.txt','w',encoding='utf-8') as myfile:
myfile.write(','.join('\n'))
但它不起作用
见下文
我看不出你一开始是在哪里读文件的。你必须先阅读你的
path_text.txt
,然后才能正确格式化,对吗这将在
content
中为您提供['/gp/oi/eu/gatk/inputs/NA12878_24RG_med.hg38.bam', '/gp/oi/eu/gatk/inputs/NA12878_24RG_small.hg38.bam']
现在,如果要将此数据写入格式为
["/gp/oi/eu/gatk/inputs/NA12878_24RG_med.hg38.bam", "/gp/oi/eu/gatk/inputs/NA12878_24RG_small.hg38.bam"]
的文件中,请执行以下操作:现在
path_json.json
文件看起来像-如果您想从文件中加载json,这是有效的json
相关问题 更多 >
编程相关推荐