Python 2.7 Can';t在python中生成正确的文件
我试图在现有文件的基础上生成一个新文件,该文件只包含一些预定义文本的行。我有:Python 2.7 Can';t在python中生成正确的文件,python-2.7,file,Python 2.7,File,我试图在现有文件的基础上生成一个新文件,该文件只包含一些预定义文本的行。我有: with open("steps_shown_at_least_once.log", "r") as f: for line in f: if line.find("Run program"): output = open('run_studio.txt', 'a') output.write(line) output.c
with open("steps_shown_at_least_once.log", "r") as f:
for line in f:
if line.find("Run program"):
output = open('run_studio.txt', 'a')
output.write(line)
output.close()
出于某种原因,这会生成一个相同的文件。但是,我正在搜索的运行程序不在旧文件的每一行中。行。find('Run program')返回字符串的索引
返回值如果找到索引,则为-1,否则为-1 可在此处找到: 而不是
line.find(“Run program”):
writeif“Run program”in line: