我正在通过在每个循环结束时循环它来执行某些任务,我想清除日志,我可以这样做,但是当我打开写入日志的文件时,我得到的前几行为空白,然后它正在写日志,为什么?
for app in someList:
with open('../logs/eachapp/migration_log.log') as logging_file:
with open(Path(str(migrated_path+"/migration_log.log")), "w") as f1:
for line in logging_file:
if line.strip() != "":
f1.write(line)
with open('../logs/eachapp/migration_log.log','r') as testing:
for line in testing:
print("$"*100)
print(line)
print(print(len(line.strip())))
with open('../logs/eachapp/migration_log.log', 'w'):
pass
正如您在上面的代码中看到的那样,在我捕获日志之后,我将其读写到某个文件夹路径中很长时间,并且在此之后我将清除日志,并在其余的迭代中再次进行相同的操作, 因此,在每次迭代之后,我都能够为该特定迭代编写日志,因为它清除了内容但将其保留为黑线,所以我一开始就得到了空行。