![](/img/trans.png)
[英]Python- How to compare a data file .json to a log file .json and output a new file .json with changes incorporated
[英]python compare and output to new file
我有一個Python腳本,按照指定的順序執行以下操作:
這是我正在努力的第4部分。 下面的代碼將一直運行到第4階段,該階段將使其余代碼停止工作:
#!/usr/bin/python
import re
import sys
import cgi
# Compare the cleaned up list of IPs against the botwatch
# list and output the results to a new file.
new_list = set()
outfile = open("final_downloads/malicious_ips", "w")
for line in open("final_downloads/ip_list_clean", "r")
if line in open("/var/www/botwatch.txt", "r")
outfile.write(line)
new_list.add(line)
outfile.close()
關於為什么最后一節不起作用的任何想法? 實際上,它阻止了整個工作。
在上一節中,您缺少一些冒號。 嘗試這個:
new_list = set()
outfile = open("final_downloads/malicious_ips", "w")
for line in open("final_downloads/ip_list_clean", "r"):
if line in open("/var/www/botwatch.txt", "r"):
outfile.write(line)
new_list.add(line)
outfile.close()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.