我试图在文本文件中制作一种日志,以避免重复工作。我有以下函数来执行此任务:
def write_to_logbook(target_name):
with open('C:\Documents\logbook.txt', 'a+') as f:
for lines in f:
if target_name not in lines:
f.write(target_name + '\n')
f.close() #when I didn't have f.close() here, it also wasn't writing to the txt file
当我在运行脚本后检查文本文件时,它保持为空。我不知道为什么。
我这样称呼它(实际上目标名称是从唯一ID中提取的,但由于我不想把所有东西都放在这里,所以这是要点):
target_name = 'abc123'
write_to_logbook(target_name)
呼如林
Helenr
相关分类