我的变量tag
在输入嵌套for
时失去了引用:
file_with_all_tags = open("tags.txt", "r")
origem = open("origem.html", "r")
for tag in file_with_all_tags:
final_file_name = "tag-" + tag + ".html"
final_file = open(final_file_name, "w")
for line in origem:
if tag in line: # HERE THE VARIABLE 'TAG' IS EMPTY
final_file.write(line)
final_file.close()
origem.close()
file_with_all_tags.close()
答案 0 :(得分:0)
问题解决了!实际上我对文件" origem.html"的迭代很累。我不得不将open()和close()函数移动到循环内部。多谢你们!谢谢@rrauenza!