如何从单个文件读取特定行并在新文件的同一行中写入?

时间:2019-05-08 15:40:33

标签: python python-3.x file-handling

import os
post_analysis_log = open("Complete_post_analysis.text",'w')

directory='/media/quinn/Joker/Anaysis/KCATBH00'

for x in range (1,6):
    os.chdir(directory +str(x)+'/')
    print(os.getcwd())
    with open ('post_analysis.log','r') as post:
        lines=post.readlines()

post_analysis_log.write("KCATBH00")
post_analysis_log.write(str(x))
post_analysis_log.write("    ")
post_analysis_log.write(lines[1])
post_analysis_log.write("    ")
post_analysis_log.write(lines[3])

这是我使用它在一行中编写的代码,但不幸的是,它在另一行中编写。

0 个答案:

没有答案
相关问题