python - 如何从单个文件中读取特定行并在新文件的同一行中写入?
问题描述
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])
这是我用它写在一行的代码,但不幸的是它写在另一行。
解决方案
推荐阅读
- ajax - Yii2 ActiveForm Ajax Validation and submit
- java - 使用 IntelliJ 开发 Eclipse RCP
- fabricjs - FabricJS 使用画布缩放调整过滤器大小
- c++ - 具有经常更改优先级的作业的优先级队列的数据结构
- c# - xamarin git pull nuget 包错误
- reactjs - 使用 apollo 进行身份验证后缓存用户
- php - 在 Laravel 视图中调用未定义的函数
- javascript - 使用angular4在innerhtml中单击操作不起作用
- javascript - 如何在指令中获取参数
- java - FileWriter / BufferedReader Java 单词查找器